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

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?


Solution 1:

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true

Solution 2:

In swift you can use this as

UIApplication.sharedApplication().idleTimerDisabled = true

Solution 3:

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true