How to run NSTimer in background and sleep in iOS?

后端 未结 6 644
南笙
南笙 2021-02-04 21:56

I found a lot of post in stackoverflow about NSTimer run in background.

However I didn\'t find any solution.

In my app , I play sound in background

6条回答
  •  猫巷女王i
    2021-02-04 22:48

    You can’t

    Timers only exist within your application. So (except for a very small window) when your app is sent to the background, timers cannot fire anymore.

    (The audio keeps running, because it’s played by the system, and not by your app.)

    So you cannot use timers for this purpose.

    What you can do — as suggested by iPatel — is use a local notification, instead. This will briefly awake your app, allowing you to stop playing the music.

提交回复
热议问题