iOSer2012 最近的时间轴更新
iOSer2012

iOSer2012

V2EX 第 159241 号会员,加入于 2016-02-17 17:23:58 +08:00
iOSer2012 最近回复了
2016-02-19 16:36:15 +08:00
回复了 wohenyingyu01 创建的主题 iDev applicationDidEnterBackground 的代码一直在跑……
2016-02-19 16:27:31 +08:00
回复了 wohenyingyu01 创建的主题 iDev applicationDidEnterBackground 的代码一直在跑……
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/
2016-02-19 16:13:57 +08:00
回复了 wohenyingyu01 创建的主题 iDev applicationDidEnterBackground 的代码一直在跑……
不应该对这个方法做这种测试,这个方法只是表明 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
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1074 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 19:07 · PVG 03:07 · LAX 11:07 · JFK 14:07
Developed with CodeLauncher
♥ Do have faith in what you're doing.