私は瞑想アプリに取り組んでいます。このアプリで私は24時間までの時間を選択し、瞑想を行うためのオプションをユーザーに与えています。タイマーはロック画面で3分間正常に動作していますが、3分後には停止しました。Swift3のロック画面でNSTimerが3分以上実行されていませんか?
コードはここにある: - 事前に
var backgroundTaskIdentifier: UIBackgroundTaskIdentifier?
var timer : Timer?
var counter : Int!
override func viewDidLoad() {
super.viewDidLoad()
backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {
UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier!)
})
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(MainPlayerMindCultivationController.updateTimer), userInfo: nil, repeats: true)
}
func updateTimer() {
counter = counter - 1
let hours = Int(counter)/3600
let minutes = Int(counter)/60 % 60
let seconds = Int(counter) % 60
timerLabel.fadeTransition(0.4)
timerLabel.text = String(format: "%02i:%02i:%02i",hours,minutes,seconds)
print("mincounter\(counter)")
}
感謝。
良いアイデアを読むにはhttps://stackoverflow.com/questions/34862160/make-timer-run-on-background-ios-for-more-than-3-minutes – iPatel