Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto lock does not function when app left open - iOS

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?

like image 671
aqsa arshad Avatar asked May 07 '26 00:05

aqsa arshad


2 Answers

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.

like image 57
aqsa arshad Avatar answered May 09 '26 12:05

aqsa arshad


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
like image 37
yflbrg Avatar answered May 09 '26 12:05

yflbrg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!