开发者

How long can an iPhone app live in the background?

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?

thank开发者_如何学Pythons, Eric


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜