Open zhaoxuezhi opened 7 years ago
能提供一下示例崩溃栈和代码吗?
0 libobjc.A.dylib objc_msgSend + 16 1 MeiJiaShi -[HLJNetworkAgent jsonResponseSerializer] (HLJNetworkAgent.m:104) 2 MeiJiaShi -[HLJNetworkAgent handleRequestResult:responseObject:error:] (HLJNetworkAgent.m:152) 3 MeiJiaShi 125-[HLJNetworkAgent dataTaskWithHTTPMethod:requestSerializer:URLString:parameters:baseRequest:constructingBodyWithBlock:error:]_block_invoke (HLJNetworkAgent.m:487) 4 MeiJiaShi 72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.150 (AFURLSessionManager.m:308) 5 libdispatch.dylib dispatch_call_block_and_release + 24 6 libdispatch.dylib dispatch_client_callout + 16 7 libdispatch.dylib dispatch_async_redirect_invoke + 1604 8 libdispatch.dylib dispatch_client_callout + 16 9 libdispatch.dylib dispatch_root_queue_drain + 1848 10 libdispatch.dylib dispatch_worker_thread3 + 108 11 libsystem_pthread.dylib _pthread_wqthread + 816
其中 HLJNetworkAgent 是仿照 YTKNetworkAgent 写的,代码逻辑完全一致;将 jsonResponseSerializer 方法在 init 方法中调用后,再无崩溃发生,麻烦分析下,是不是多线程访问引起的奔溃。
在YTKNetworkAgent.m 文件, 的上述方法在异步线程调用, 不是线程安全的 , 在 app 启动瞬间有多个请求发起,会有崩溃