系统版本:iOS12
build configuration: Release
场景: 后台收到Push进入前台,触发网络请求。
Xcode 输出:
nw_socket_handle_socket_event [C58:1] Socket SO_ERROR [9: Bad file descriptor]
nw_socket_get_input_frames [C58:1] recvmsg(fd 33, 1024 bytes) [57: Socket is not connected]
[BoringSSL] nw_protocol_boringssl_error(1584) C49.1:2 Lower protocol stack error: 53
load failed with error Error Domain=NSPOSIXErrorDomain Code=53 “Software caused connection abort”
BoringSSL,可能与ssl有关
经过搜索发现是苹果iOS 12的一个bug, 目前好像没有很好的解决方法。参考:https://github.com/AFNetworking/AFNetworking/issues/4279
App返回前台后,延迟访问网络,可以暂时解决这个问题:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.sessionManager?.get("https://reqres.in/api/users", parameters: nil, progress: nil, success: { (task, data) in
print("success")
}, failure: { (task, error) in
print("failure \(error.localizedDescription)")
})
}