iPhone: Run in the background indefinitely

2019-06-14 19:14发布

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...

6条回答
叼着烟拽天下
2楼-- · 2019-06-14 19:47

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.

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-14 19:48

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.

查看更多
爷的心禁止访问
4楼-- · 2019-06-14 19:54

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?

查看更多
祖国的老花朵
5楼-- · 2019-06-14 20:08

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!

查看更多
劳资没心,怎么记你
6楼-- · 2019-06-14 20:10

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.

查看更多
叼着烟拽天下
7楼-- · 2019-06-14 20:13

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

查看更多
登录 后发表回答