在开发中,如遇到类似的崩溃情况,可以参考尝试以下解决方法
崩溃情况
-[AFHTTPResponseSerializer validateResponse:data:error:] (AFURLResponseSerialization.m:)
-[AFJSONResponseSerializer responseObjectForResponse:data:error:] (AFURLResponseSerialization.m)
[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.108 (AFURLSessionManager.m)
解决办法
这个问题和AFNetworking无关,当我们使用单例封装时,我们应该锁定 requestSerializer 和 responseSerializer 而不是延迟加载。
- (AFJSONResponseSerializer *)afJSONResponseSerializer {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_afJSONResponseSerializer = [AFJSONResponseSerializer serializer];
});
return _afJSONResponseSerializer;
}
- (AFJSONRequestSerializer *)afJSONRequestSerializer {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_afJSONRequestSerializer = [AFJSONRequestSerializer serializer];
});
return _afJSONRequestSerializer;
}