❤️ Please consider supporting my work, become my Sponsor! 🙏
Micro library to answer to questions like:
- How to prevent screen lock on my application?
- How can I prevent the display on an iOS device from dimming and turning off?
- How do I prevent the iPhone screen from dimming or turning off while certain ViewController is presented?
Well... Sometimes you want your iPhone to stay active a little bit longer is it an import or just game interface.
This project aims to simplify the code and give you a well tested solution.
.disabled
- Nothing will change (disabled functionality)..always
- Your iOS device will never timeout and go to sleep..whenCharging
- Device will stay active as long as it's connected to charger.
Important: If Insomnia instance is deallocated, it's functionality is automatically disabled and device will behave nominally (timeout, disable screen and lock).
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .always)
}
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .whenCharging)
}
final class SomeViewController: UIViewController {
private let insomnia = Insomnia(mode: .always)
}
insomnia.mode = .always
The too simple answer is:
UIApplication.shared.isIdleTimerDisabled = true
The problem with this solution is that you have to remember to change this global variable to false
when it's no longer needed.
What if you want to activate it only when your device is on charger?
Logo design by Artur Martynowski - check his dribble profile, he's really great!