views:

282

answers:

1

I started a few days ago to experiment development for the iPhone platform, and while reading about it's multi-tasking capabilities I found out the "task completion", which can be very useful.

I googled a little, read the documentation available at developer.apple.com/iphone, but still haven't found something: is there a way to have this task completion run a loop (possibly an infinite one), or a timer which would run like every 10 minutes?

I know it's like "cheating" and they probably have some countermeasures, but anyway, it'd be a good thing to try :)

+2  A: 

With task completion? No. However, you can say your app is an audio app with background capabilities for example, set up an audio session with the kAudioSessionProperty_OverrideCategoryMixWithOthers property, loop some audio that plays no sound. This will let the user exit, launch iPod or whatnot, and have it play as normal while your app continues to run.

I've tested this in a sample app, and it works. However, it's dubious and I wouldn't recommend it. (It's also likely to be rejected if Apple ever finds out.)

jer
You can have only one background audio app at a time, or can you have multiple? It seems that if the user opens the iPod app or something like Pandora, your app would be made inactive.
lucius
So long as the application that is opening the audio device uses that property I defined above, you can have as many audio sources playing as you want. However, apps like iPod don't. They will stop playing if someone else wants access to the audio. But, if you start up an app using the above property, that will keep playing even though iPod has requested access, and iPod won't care because it got access. The system is smart enough to let iPod play, but knows enough not to stop the other app since it mixes well with others.
jer
I still haven't been able to try this out, it was a rather theoretical question, I have to admit, but that seemed like a great way to enforce keeping the application open on the background. It's sad that probably this'll drain the battery quite quickly, especially when combined with other applications or different processing tasks run by this same app.
wintermute
Oh definitely, it likely won't bode well for your battery time (of course, won't eat through it like it would if you were using a location based background app or a voip app)... But yeah, definitely not battery friendly.
jer
[PasteBot tried this background audio hack](http://tapbots.com/blog/pastebot/pastebot-music-in-background) and Apple rejected it, saying that you have to either play some kind of audio, or remove that feature. So here's a real-world example of someone trying to be clever and work around the limitation, technically within the rules, but violating the spirit of the law.
lucius
Ah, interesting. Didn't know that this was in the wild more than I've made it here on SO (second time now I've posted this).
jer
Actually, <a href="http://www.cultofmac.com/pastebot-uses-music-to-get-around-ios-4-multitasking-limitations/53686">pastebot got accepted</a> after they gave users the choice on which track to loop in the background. Any more success / failure stories on using the backgrounding capabilities in a manner that wasn't envisioned by Apple. (for example: Using the voip-hook to wake a rss-application up every 10 mins?)
TumbleCow