0

So I need this app to run timer for more than 3 minutes, and play a sound like very 45 seconds, most of the solutions here are just for less than 3 minutes on iOS. Is there a way to make it run all the time, unless the app stops?

After the research, I guess the solution is implement beginBackgroundTaskWithExpirationHandler

and stops it by giving a handler and set location update on plist?

As for audio, besides setting the plist, anything else need to do to play audio?

Swift how to use NSTimer background? iphone - NSTimers in background Run app for more than 10 minutes in background

Community
  • 1
  • 1
martingale
  • 45
  • 1
  • 7

1 Answers1

2

No, in order to save all of us from apps that kill our batteries, Apple does not allow apps to continue to run in the background for more than a few minutes. There are only very special limitations (music playing apps, VOIP, navigation apps, etc.) which permit ongoing operation. In terms of details, this is described in About the Background Execution Sequence.

If you want to notify user of something at some future time, you can use local notifications. When you do this, though, you don't control whether your app restarts or not. Only if the user taps on the notification (assuming they even granted your app notification privileges at all), will the app be reopened. For more information, refer the the local notification discussions in UserNotification framework documentation. But note, this is not intended for alerts every 45 seconds, but rather for a significant notification scheduled for some future time.

For discussion of how one might marry local notifications with timers, see swift NSTimer in Background and this follow up question swift calculate time for timers running in background.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I have this timer app ..it is obviously running at background after I tapped the home button, it can run like an hour..!! It gives beep every 1 minutes and when I get in the timer is still on. – martingale Jan 18 '16 at 19:47