make timer run on background iOS for more than 3 minutes

泄露秘密 提交于 2019-11-26 23:35:16

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/34862160/make-timer-run-on-background-ios-for-more-than-3-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!