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

前端 未结 5 998
天命终不由人
天命终不由人 2020-12-02 06:53

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?

5条回答
  •  孤街浪徒
    2020-12-02 07:12

    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.

提交回复
热议问题