Fix server media progress JSON decoding

This commit is contained in:
ronaldheft 2022-08-18 15:55:50 -04:00
parent add64249cd
commit a82474cf45
4 changed files with 31 additions and 25 deletions

View file

@ -55,8 +55,14 @@ extension KeyedDecodingContainer {
extension CAPPluginCall {
func getJson<T: Decodable>(_ key: String, type: T.Type) -> T? {
guard let value = getObject(key) else { return nil }
guard let json = try? JSONSerialization.data(withJSONObject: value) else { return nil }
return try? JSONDecoder().decode(type, from: json)
do {
let json = try JSONSerialization.data(withJSONObject: value)
return try JSONDecoder().decode(type, from: json)
} catch {
NSLog("Failed to get json for \(key)")
debugPrint(error)
return nil
}
}
}