Why does connecting back to an iOS background NSURLSession take too long waiting on a lock, crashing the app?

拟墨画扇 提交于 2020-01-12 18:51:48

问题


Why would connecting with an NSURLSession through its configuration take so long that it would crash the app on start up: 'failed to launch in time'?

I've seen similar crash dumps in many iOS apps including NY Times iOS app and Evernote app.

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

Here's the stack trace:

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

回答1:


See Application Specific Information: Application failed to launch in time (iOS)? .

Basically there are 2 things to keep in mind:

  1. Upon startup, you only have a few seconds to finish the startup procedure. Any longer running code should be called asynchronously after the app has started.

  2. Make absolutely sure that any UI code in your callbacks/blocks/closures/etc... is called on the main thread. You must force it to do so.



来源:https://stackoverflow.com/questions/25679257/why-does-connecting-back-to-an-ios-background-nsurlsession-take-too-long-waiting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!