Auto lock does not function when app left open - iOS

2.1k Views Asked by At

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?

2

There are 2 best solutions below

0
aqsa arshad On BEST ANSWER

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.

1
yflbrg On

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