tags:

views:

39

answers:

1

I can't seem to find a clear answer to this-- I'm spec'ing out an iPhone app that I'd like to have live in the background and notify the user at certain periods throughout the day. So the user would launch the app in the morning and then continue to use their phone, then every few hours the app would pop open a notification dialog.

Will my app ever be shut down (automatically) by the OS? Or will it just live forever, notifying user when it needs to?

thanks, Eric

+2  A: 

Basically there are three kinds of running in the background on iOS 4:

  1. Running in the background to "finish" stuff (e.g. upload a posting or a picture, finish processing something etc.). You ask the OS to grant you extra time after the user switches to another app, and it will tell you how much time you got. You can't run in the background for an indefinite time.

  2. Running in the background to do specific stuff: VoIP, tracking location (e.g. for GPS navigation), or playing audio. You can only do the stuff that you told the OS you would do in the background.

  3. Local notifications (UILocalNotification). From your description, this is what you're looking for. You're not actually running, you just schedule notifications, and when it's time to notify the user, they'll be notified and can go to your app. If you need to notify the user dynamically (i.e. you don't know ahead at what times they need to be notified and it's not location or VoIP triggered), you might want to look into push notifications.

Apple has a good overview here: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

xtina
Thanks, that's fantastic, and I think you're right-- UILocalNotification will probably do what I want.Curious, for the 2nd type of background processing (that you describe above), am I limited to only doing VoIP, location tracking and audio types of activities? Or can I do whatever I want in the background?
Eric
Pretty much. For continuous background operation, there are currently only these three types of activities permitted. You're limited both contractually (App Store) to doing what you said you would do, as well as by the types of API calls you can make, e.g. when you said you would do background audio and then go and call an OpenGL ES function, you'll be killed right away.
xtina
Ah, one additional note though. Recently, a developer tried to circumvent this by simply playing silent audio AND doing additional stuff (that did not touch any of the "kill right away" type of functionality). The app was rejected, BUT Apple apparently told them that if they played useful audio instead of silence, the app could be approved (even though it was doing more than just playing audio): http://tapbots.com/blog/pastebot/pastebot-music-in-background
xtina
Huh, very cool. Thanks again for the comprehensive info.
Eric