How to prevent the screen from sleeping in iOS?


In this post we will be seeing how to prevent screen from sleeping in iOS.

So, let’s get started.

Copy the below line of code in viewDidLoad method in ViewController.Swift

override func viewDidLoad() {
   super.viewDidLoad()
   // Do any additional setup after loading the view, typically from a nib.
   UIApplication.shared.isIdleTimerDisabled = true
}

Run the application, the application will never go in sleep mode.

Updated on: 16-Dec-2019

276 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements