How do I prevent the iPhone screen from dimming or turning off while my application is running?

IosUiapplication

Ios Problem Overview


I'm working on an app that requires no user input, but I don't want the iPhone to enter the power saving mode.

Is it possible to disable power saving from an app?

Ios Solutions


Solution 1 - Ios

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true

Solution 2 - Ios

In swift you can use this as

UIApplication.sharedApplication().idleTimerDisabled = true

Solution 3 - Ios

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true

Solution 4 - Ios

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.

Solution 5 - Ios

We were having the same issue. Turned out to be a rogue process on our MDM server that was deleted in our account but on the server was still sending the command to dim our devices.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlajosView Question on Stackoverflow
Solution 1 - IoslajosView Answer on Stackoverflow
Solution 2 - IosVettiyanakanView Answer on Stackoverflow
Solution 3 - IosCharlie SeligmanView Answer on Stackoverflow
Solution 4 - IosJMStudios.jrichardsonView Answer on Stackoverflow
Solution 5 - IosJMStudios.jrichardsonView Answer on Stackoverflow