How to prevent screen lock on my application with swift on iOS

alvarogalia picture alvarogalia · Feb 4, 2015 · Viewed 49.8k times · Source

How can I prevent screen lock only when using Navigation?

Waze has the option to do that, how can I do this in my App?

Answer

atwalsh picture atwalsh · Feb 4, 2015

Use this:

Objective-C:

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

Swift (legacy):

UIApplication.sharedApplication().idleTimerDisabled = true

Swift 3 and above:

UIApplication.shared.isIdleTimerDisabled = true

Make sure to import UIKit.

Here is the link to the documentation from apple.developer.com.