How to run NSTimer in background and sleep in iOS?

后端 未结 6 627
南笙
南笙 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条回答
  •  逝去的感伤
    2021-02-04 22:37

    With Swift

    let app = UIApplication.sharedApplication()
    app.beginBackgroundTaskWithExpirationHandler(nil)
    let timer = NSTimer.scheduledTimerWithTimeInterval(1,
                target: self,
                selector:"DoSomethingFunctions",
                userInfo: nil,
                repeats: true)
    NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
    

提交回复
热议问题