Je travaille sur une application de méditation. Dans cette application, je donne une option à l'utilisateur pour sélectionner l'heure jusqu'à 24 heures et faire de la méditation. La minuterie fonctionne correctement pendant 3 min sur l'écran de verrouillage, mais après 3 minutes, elle s'est arrêtée.NSTimer ne fonctionne pas plus de 3 min sur l'écran de verrouillage dans Swift3?
codeest ici: -
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)")
}
Merci à l'avance.
Pour une meilleure idée, lisez https://stackoverflow.com/questions/34862160/make-timer-run-on-background-ios-for-more-than-3-minutes – iPatel