Objective-C
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Swift
UIApplication.shared.isIdleTimerDisabled = true
In swift you can use this as
UIApplication.sharedApplication().idleTimerDisabled = true
Swift 3:
UIApplication.shared.isIdleTimerDisabled = true
I have put this line of code in my view controller yet we still get customers saying the screen will dim or turn off until someone touches the screen. I have seen other posts where not only do you programatically set
UIApplication.sharedApplication().idleTimerDisabled = true
to true but you must reset it to false first
UIApplication.sharedApplication().idleTimerDisabled = false
UIApplication.sharedApplication().idleTimerDisabled = true
Sadly this still did not work and customers are still getting dimmed screens. We have Apple Configurator profile preventing the device from going to sleep, and still some devices screen go dim and the customer needs to press the home button to wake the screen. I now put this code into a timer that fires every 2.5 hours to reset the idle timer, hopefully this will work.
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