I'm developing a messaging app and auto lock doesn't function when app left open. (No single line is related to auto lock in code)
I've used this line to enabling it,
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
but its not working.
Any idea how to get this done?
For anyone who is facing the same issue.
The device will not lock when you are running app through X-code either debugging or not. Once app is installed you have to detach it from X-code( just remove the attached cable ), it will work for you.
For others who may encounter this, in my case, it was the AVPlayer who prevented the display from going to sleep. To solve this, use the preventsDisplaySleepDuringVideoPlayback property of AVPlayer:
let player = AVPlayer()
player.preventsDisplaySleepDuringVideoPlayback = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With