![](/img/trans.png)
[英]How to prevent app crashing when uploading image when there is no internet connection
[英]prevent app from crashing if there is no internet
沒有互聯網時,我的應用程序崩潰了。 這是因為
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers error:&error];
返回錯誤'data parameter is nil'
。
當我使用SDWebImage緩存jsonData
時,如何防止崩潰。 因此,即使沒有互聯網,它也應該在那里!
您可以確保僅在數據不為nil的情況下執行代碼:
if (jsonData) {
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers error:&error];
}
不僅不能處理nil,而且不能正確處理json的格式,因此您可能會得到錯誤消息msg
@try {
responseDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
}
@catch (NSException *exception) {
NSLog(@"exception %@",exception);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.