Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long can an iPhone app live in the background?

Tags:

ios

iphone

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

like image 296
Eric Avatar asked Aug 06 '10 23:08

Eric


People also ask

How long do apps stay on background iOS?

Typically, iOS policies permit up to 10 minutes of background time after the app is suspended or the device is locked. In practice this time can vary wildly, but we request as much time as the system will allow.

How long can an app run in the background?

As long as the app is running in the foreground, everything is fine. But when the app is put in the background, the system kills the app after a indeterminate amount of time. The app can hang in there anywhere from 2 - 15 minutes.

Do iPhone apps run in the background?

Some apps keep running in the background when you return to the home screen. You can set your mobile phone to refresh apps in the background so that you'll still get notifications even if the app isn't actively in use. Tap Settings. Tap General.

Do iPhone apps close automatically?

Plus, iOS closes apps automatically as it needs more memory, so you're doing something your device is already doing for you.


1 Answers

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: https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence

like image 80
puzzle Avatar answered Sep 21 '22 11:09

puzzle