为什么连接回iOS背景NSURLSession等待锁定需要太长时间,导致应用程序崩溃?

为什么通过其配置与NSURLSession连接需要花费很长时间才能在启动时使应用程序崩溃:“未能及时启动”?

我在许多iOS应用程序中看到了类似的故障转储,包括NY Times iOS应用程序和Evernote应用程序。

[NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:queue] 

这是堆栈跟踪:

 Thread 0: 0 libsystem_kernel.dylib 0x3afb7aa0 semaphore_wait_trap + 8 1 libdispatch.dylib 0x3af04d3d _dispatch_semaphore_wait_slow + 173 2 CFNetwork 0x2febd8e3 -[__NSCFBackgroundSessionBridge setupBackgroundSession] + 379 3 CFNetwork 0x2fef18a1 +[__NSCFSessionBridge bridgeForConfiguration:session:queue:] + 153 4 CFNetwork 0x2fef6497 -[__NSCFURLSession initWithConfiguration:delegate:delegateQueue:] + 395 5 CFNetwork 0x2fef6eb7 +[__NSCFURLSession sessionWithConfiguration:delegate:delegateQueue:] + 295 

请参阅应用程序特定信息:应用程序未能及时启动(iOS)? 。

基本上要记住两件事:

  1. 启动时,您只需几秒钟即可完成启动过程。 应用程序启动后,应该异步调用任何运行较长的代码。

  2. 确保在主线程上调用回调/块/闭包/等中的任何UI代码。 你必须强迫它这样做。