I want screen always light when playing audio, and turn dark when complete the audio and I do not tap the screen after two minutes(i have set auto-lock in setting), implement code as the following.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.isIdleTimerDisabled = true
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
UIApplication.shared.isIdleTimerDisabled = false
}
But the result is screen turn dark immediately when finish one audio which is more than two minutes.
How to fix it ,or is this ios bug?
Thanks
Seems like there isn't any opportunity to reset idle timer thus your device goes off immediately after the
isIdleTimerDisabled
-property set.Yet you still can try to implement your own timer to turn it off in right time.
Unfortunately, there still isn't any way to check current
idleTimer
time to calculateinterval
value dynamically.