I am working on a meditation app. In this app i am giving an option to the user to select the time up to 24hrs and do meditation. Timer is working fine for 3 min on lock screen but after 3 min it stopped.
Code is here :-
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)")
}
Thanks in Advance.