2
icodesign 2016-02-19 15:33:09 +08:00
没人跟你说跑 5 秒
|
3
iOSer2012 2016-02-19 16:13:57 +08:00 1
不应该对这个方法做这种测试,这个方法只是表明 application 到了后台。这个方法根据官方文档
Your implementation of this method has approximately five seconds to perform any tasks and return. If you need additional time to perform any final tasks, you can request additional execution time from the system by calling beginBackgroundTaskWithExpirationHandler:. In practice, you should return from applicationDidEnterBackground: as quickly as possible. If the method does not return before time runs out your app is terminated and purged from memory. You should perform any tasks relating to adjusting your user interface before this method exits but other tasks (such as saving state) should be moved to a concurrent dispatch queue or secondary thread as needed. Because it's likely any background tasks you start in applicationDidEnterBackground: will not run until after that method exits, you should request additional background execution time before starting those tasks. In other words, first call beginBackgroundTaskWithExpirationHandler: and then run the task on a dispatch queue or secondary thread. 更不应该在这个方法使用死循环来测试 application 会不会被系统 kill |
4
loveuqian 2016-02-19 16:15:54 +08:00 via iPhone
|
5
iOSer2012 2016-02-19 16:27:31 +08:00
iOS 支持的后台任务有限,基本上就是音频,位置相关 ,voip, 蓝牙
,详细看 Table 3-1 Background modes for apps https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html 还有一个中文的 https://github.com/bboyfeiyu/iOS-tech-frontier/blob/master/issue-3/iOS%E5%90%8E%E5%8F%B0%E6%A8%A1%E5%BC%8F%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97.md iOS7 以后 又增加了几个:后台获取,远程通知的后台处理, URLSession 的后台传输的处理 http://objccn.io/issue-5-5/ |
6
iOSer2012 2016-02-19 16:36:15 +08:00
|
7
wohenyingyu01 OP @iOSer2012 我就是看文档说 approximately 5 seconds 的,为什么说不能测试呢?看到了就想去证实一下应该是本能反应吧…我知道如何延长时限,就是想试试被系统结束的极限条件是什么……
|
8
wadahana 2016-02-25 15:33:50 +08:00 1
ios7 以上正常可以活 180s ; ios6 好像是 300 or 600s 忘了。
[[UIApplication sharedApplication] backgroundTimeRemaining] 可以读到还能活多久 后台下载用 NSURLSession 如果只需要激活几次偷偷写数据,用 GPS |
9
wohenyingyu01 OP @wadahana 老司机!!!谢谢
|