I am using this in my appdelegate\'s applicationDidFinishLaunching: method to make sure the iPhone doesn\'t go to sleep during the time the app is open
[appl
Instead of Appdelegate, It is better to use it in a specific view controller in which you want screen light to be alive.
Swift 5.0 Version:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.isIdleTimerDisabled = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.isIdleTimerDisabled = false
}