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.