简体   繁体   English

即使在睡眠或重启后,也会在后台持续运行IOS应用程序

[英]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.

相关问题 iOS 应用程序在后台连续运行 - iOS app to run continuously in background 在后台持续运行应用程序 - to run app continuously in the background 即使在“plist”中的“UIBackgroundModes”中出现“voip”,iOS iOS中的设备重启后iOS App也不会自动启动 - Even with “voip” present in “UIBackgroundModes” in “plist”, iOS App does not auto start after device reboot in iOS10 重启后使用BLE的iOS后台服务 - iOS background service using BLE after reboot 如何在iOS中连续在后台运行位置更新 - How to run location updates in background continuously in ios 如何在后台运行 NSTimer 并在 iOS 中休眠? - How to run NSTimer in background and sleep in iOS? 如果UIBackgroundModes中定义的远程通知和新推送通知到来,iOS是否会在重启后启动应用程序? - Does iOS start app in background after reboot if remote-notification defined in UIBackgroundModes and new push notification comes? 即使应用处于暂停状态,如何在ios中运行后台服务 - How to run Background service in ios even when app is in suspended state ios - 我可以运行后台线程甚至应用程序已关闭 - ios - Can I run background thread even app is turned off 即使应用程序在 iOS 中终止,我们还能运行后台任务吗 - Can we run background task even app is terminated in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM