[英]Continuously run an IOS app in the background even after sleep or reboot
I need to run an iPhone app in the background continuously so that it can respond to events thrown by CTCallCenter and CTTelephonyCenter. 我需要在后台持续运行iPhone应用程序,以便它可以响应CTCallCenter和CTTelephonyCenter抛出的事件。 I have been using Private API's but can not jailbreak the phone.
我一直在使用私有API,但不能越狱手机。 By using Location and VOIP background modes, I have been able to run in the background past the IOS 10 minute limit.
通过使用位置和VOIP背景模式,我已经能够在超过IOS 10分钟限制的后台运行。 Everything works well as long as the iPhone remains active, however, when the system has been asleep for too long or rebooted, the application no longer receives events thrown by CTCallCenter and CTTelephonyCenter and stops regularly logging its background tasks.
只要iPhone保持活动状态,一切运行良好,但是,当系统长时间睡眠或重新启动时,应用程序不再接收CTCallCenter和CTTelephonyCenter抛出的事件,并停止定期记录其后台任务。 It can however receive location events at which time it runs for a short period then is suspended again.
然而,它可以接收位置事件,此时它会运行一段时间,然后再次暂停。
How can I ensure that the app always remains in an active background state, even after sleep or reboot? 即使在睡眠或重启后,如何确保应用程序始终保持活动的后台状态?
I have been able to keep the app running after sleep without jailbreaking the phone or using private API's. 我已经能够在睡眠后保持应用程序运行而不会越狱手机或使用私有API。 As I suspected it was possible, after all, I've seen other apps do it.
我怀疑它是可能的,毕竟,我已经看到其他应用程序这样做了。
The key to keep the app awake is to play an empty background audio in an infinite loop. 让应用程序保持清醒的关键是在无限循环中播放空背景音频。 Permissions required are VOIP and Audio.
需要的权限是VOIP和音频。 Even if the phone is asleep for hours the background loop will keep executing.
即使手机睡了几个小时,背景循环也会继续执行。
The second part of this article describes this approach: http://hayageek.com/ios-long-running-background-task/ 本文的第二部分描述了这种方法: http : //hayageek.com/ios-long-running-background-task/
Here is a link to an example iPhone app: http://hayageek.s3.amazonaws.com/downloads/ios/LongRunningBackgroundTask.zip 以下是一个示例iPhone应用程序的链接: http : //hayageek.s3.amazonaws.com/downloads/ios/LongRunningBackgroundTask.zip
Edit: To lower battery usage it is possible to run the audio for brief intervals only in applicationDidEnterBackground, which will reset the value of UIApplication.sharedApplication().backgroundTimeRemaining 编辑:为了降低电池使用量,可以仅在applicationDidEnterBackground中短暂运行音频,这将重置UIApplication.sharedApplication()的值.backgroundTimeRemaining
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.