[ACCEPTED]-How do I prevent the iPhone screen from dimming or turning off while my application is running?-uiapplication

Accepted answer
Score: 183

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true

0

Score: 22

In swift you can use this as

UIApplication.sharedApplication().idleTimerDisabled = true

0

Score: 12

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true

0

Score: 2

I have put this line of code in my view 14 controller yet we still get customers saying 13 the screen will dim or turn off until someone 12 touches the screen. I have seen other posts 11 where not only do you programatically set 10

UIApplication.sharedApplication().idleTimerDisabled = true 

to true but you must reset it to false first

UIApplication.sharedApplication().idleTimerDisabled = false
UIApplication.sharedApplication().idleTimerDisabled = true

Sadly 9 this still did not work and customers are 8 still getting dimmed screens. We have Apple 7 Configurator profile preventing the device 6 from going to sleep, and still some devices 5 screen go dim and the customer needs to 4 press the home button to wake the screen. I 3 now put this code into a timer that fires 2 every 2.5 hours to reset the idle timer, hopefully 1 this will work.

Score: 0

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

More Related questions