iPhone: Run in the background indefinitely
Asked Answered
M

6

-2

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

Moats answered 9/8, 2011 at 14:53 Comment(3)
Are you wanting the app start automatically on startup?Bareback
@Bareback At some point, yes. But for the purposes of this question I do not need it. If you know how to feel free to elaborate.Moats
Did you end up going to Apple about this (as suggested in the answer you suggested), and if so, what was the outcome?Pierson
P
1

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.

Prussian answered 9/8, 2011 at 15:0 Comment(3)
Do you happen to know how to request something like this from apple?Moats
I don't think Apple has ever done this or will ever do it. They have a strict set of rules that I don't think they'll break for a single application. Additionally, they will probably need to update the software on the devices to support this kind of tasks.Stalnaker
@JoshuaAbrams, to request a feature generally, file a bug. If you really think your app is so innovative and compelling that Apple might actually consider letting your app run in the background, you'll want to talk to them more directly. I'd start by contacting Apple Developer Relations -- you can find contact info on the developer web site. Bear in mind, though, that there are hundreds of thousands of approved apps, so they've probably considered most use cases already.Prussian
W
0

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

Worldwide answered 9/8, 2011 at 14:58 Comment(2)
Suppose I had another background task which was to use bluetooth to talk to another device, indefinitely. Is that supported?Moats
No. Only audio, location and voip tasks.Stalnaker
B
0

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.

Beshrew answered 9/8, 2011 at 14:58 Comment(0)
S
0

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.

Sevenup answered 9/8, 2011 at 15:0 Comment(0)
M
0

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?

Mayweed answered 9/8, 2011 at 15:17 Comment(5)
Can you please elaborate on the use of background notifications. How could this be done?Moats
You'd have to tell us more about what you're trying to achieve.Mayweed
Suppose I would like to check if a file exists and then sleep for one second; Repeating this foreverMoats
I wouldn't, but it is similar enough to what I will need to be doing so I was using it as an example.Moats
I don't see how anyone can help unless you say what you are trying to achieve and why.Mayweed
S
0

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!

Spool answered 9/8, 2011 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.