首先,我知道仅支持 voip、音频和位置应用程序在后台运行,并且它们只会在播放音频或使用位置服务等时运行。
我想知道的是是否有一种让我的应用程序在后台完全运行的方法,对电池寿命的影响无关紧要。
这样,我的应用程序的用户就可以从设置中进行选择,以便在他想要的时候并且只在他希望的时间内保持应用程序的活动状态。例如,如果他正在等待需要应用程序运行的某些内容,则在收到消息后,他可以关闭保持活动功能。
我不知道这是否可能,但我读过一些这样说的帖子,但不幸的是他们没有说如何 =(
更新:在 本教程,我发现 Acrobits 在 Apple Store 上有两个应用程序“可以强制应用程序保持活动状态并处于唤醒状态”在后台”。那么有办法做到这一点吗?
first of all, I know there is only support for voip, audio and location apps to run in background and that they will run just while the audio is been played or while using location services, etc.
What I want to know is if there is a way to keep my app running on background fully operational, doesn't matter the impact on battery's life.
That way the user of my app can select from settings to keep alive the app whenever he wants and just for the amount of time he wish. e.g if he is waiting for something that requires the app to be running, after receiving the messages he can turn off the keep alive functionality.
I don't know if this is possible but I had read some post that say so but unfortunately they didn't say how to =(
UPDATE: In this tutorial, I found that Acrobits has two apps on the Apple Store that "can force the application to stay alive and awake in the background". So there is a way to do this?
发布评论
评论(6)
从 iOS 7 开始,应用程序有更新的方式在后台运行。苹果现在认识到应用程序必须不断下载和处理数据。
这是可以在后台运行的所有应用程序的新列表。
您可以声明应用程序受支持使用 X Code 5+ 的 Info.plist 中的后台任务。例如。将 UIBackgroundModes 键添加到应用程序的 Info.plist 文件并向数组添加“fetch”值可让您的应用程序定期从网络下载和处理少量内容。您可以在 XCode 5 中的应用程序属性的“功能”选项卡中执行相同的操作(附加快照)
您可以找到 Apple 文档中有更多相关信息
From ioS 7 onwards, there are newer ways for apps to run in background. Apple now recognizes that apps have to constantly download and process data constantly.
Here is the new list of all the apps which can run in background.
You can declare app's supported background tasks in Info.plist using X Code 5+. For eg. adding UIBackgroundModes key to your app’s Info.plist file and adding a value of 'fetch' to the array allows your app to regularly download and processes small amounts of content from the network. You can do the same in the 'capabilities' tab of Application properties in XCode 5 (attaching a snapshot)
You can find more about this in Apple documentation
在您的应用程序被定向到后台后,您可以在有限的时间内执行任务,但仅限于提供的持续时间。运行时间超过此时间将导致您的应用程序被终止。请参阅“在后台完成长时间运行的任务”部分。
其他人则利用在后台播放音频作为后台进程保持活力的一种手段,但苹果只会在音频播放是合法功能的情况下接受这样的应用程序。 Apple 发布的审查指南第 2.16 条规定:
You can perform tasks for a limited time after your application is directed to go to the background, but only for the duration provided. Running for longer than this will cause your application to be terminated. See the "Completing a Long-Running Task in the Background" section of the iOS Application Programming Guide for how to go about this.
Others have piggybacked on playing audio in the background as a means of staying alive as a background process, but Apple will only accept such an application if the audio playback is a legitimate function. Item 2.16 on Apple's published review guidelines states:
如果任何后台任务运行超过10分钟,则该任务将被挂起,并调用beginBackgroundTaskWithExpirationHandler指定的代码块来清理该任务。后台剩余时间可以通过[[UIApplication共享应用]backgroundTimeRemaining]检查。
最初,当应用程序处于前台时,backgroundTimeRemaining 设置为更大的值。当应用程序进入后台时,您可以看到backgroundTimeRemaining值从599.XXX(1o分钟)减少。一旦backgroundTimeRemaining变为零,后台任务将被挂起。
If any background task runs more than 10 minutes,then the task will be suspended and code block specified with beginBackgroundTaskWithExpirationHandler is called to clean up the task. background remaining time can be checked with [[UIApplication sharedApplication] backgroundTimeRemaining].
Initially when the App is in foreground backgroundTimeRemaining is set to bigger value. When the app goes to background, you can see backgroundTimeRemaining value decreases from 599.XXX ( 1o minutes). once the backgroundTimeRemaining becomes ZERO, the background task will be suspended.
要在原生 iOS 设备上运行,请将您的应用程序设为音频播放器/录音机或 VOIP 应用程序,将其设为合法的应用程序以提交到应用程序商店,如果仅供您自己使用,则将其设为假冒应用程序。
即使这样也不会让应用程序“完全可操作”,无论是什么,而是仅限于有限的 API。
For running on stock iOS devices, make your app an audio player/recorder or a VOIP app, a legitimate one for submitting to the App store, or a fake one if only for your own use.
Even this won't make an app "fully operational" whatever that is, but restricted to limited APIs.
取决于它做什么。如果您的应用程序占用了太多内存,或者调用了不应调用的函数/类,SpringBoard 可能会终止它。然而,它很可能会被苹果拒绝,因为它不遵循他们的 7 个背景用途。
Depends what it does. If your app takes up too much memory, or makes calls to functions/classes it shouldn't, SpringBoard may terminate it. However, it will most likely be rejected by Apple, as it does not follow their 7 background uses.
可能该链接将帮助 bcz 你可能必须在后台运行的应用程序方法中实现 Appdelegate 中的代码..
另请参阅developer.apple.com 网站了解应用程序类
这里是运行应用程序的链接在后台
May be the link will Help bcz u might have to implement the code in Appdelegate in app run in background method ..
Also consult the developer.apple.com site for application class
Here is link for runing app in background