开发者

iPhone: Run in the background indefinitely

开发者 https://www.devze.com 2023-03-27 07:57 出处:网络
I am looking for a way to have an iPhone application run in the background indefinitely. This app will not be 开发者_开发问答using location services or VoIP, but instead be preforming a specific task

I am looking for a way to have an iPhone application run in the background indefinitely. This app will not be 开发者_开发问答using location services or VoIP, but instead be preforming a specific task (sorry but I cannot explicitly say what the task is). The task can be comparable to checking to see if a file exists and then sleeping for 1 second. For the purpose of this question, the task should be running forever.

Any help would be appreciated. As far as I can tell from iPhone documentation what I am requesting is not possible, so I am rather stumped...


You're right -- unless your reason for running in the background fits within one of the categories that Apple has defined (playing audio, voip, etc.), your app won't be allowed to run indefinitely in the background. If the reason you want to do that is really compelling, you might want to talk to Apple about getting them to allow it. Expect a long uphill battle, though. A more pragmatic approach would be to look for ways that you can achieve the same effect, like running your background code on a server or registering for various notifications from the system.


This cannot be done with the current SDK. Apps on the background can only use specific services (audio, location, ...).


Multitasking on iOS is described here. http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH5

The permissible types of multitasking are audio, location, and voip, so it sounds like your task may be impossible on iOS.


This can only be done on a jailbroken environment. If that's not an option for you, than the SDK does not currently support long-term background activity without it being for audio, location, or voip purposes.


As already discussed true background processing will not be possible for your requirements.

However, maybe you could make use of background notifications to achieve your ends?


A disappointing question but still I am answering you for just providing the logic. Although its not acceptable during app store review process.

while (your condition)

{ NSAutoreleasePool *aPool = [[NSAutoreleasePool alloc ] init];

  // do your desired task here

[aPool release] }

Call this in applicationDidEnterBackground and see whats happening at the instruments to get a good knowledge of background working.

Happy Coding!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号