ochococo/Insomnia
Fork: 15 Star: 109 (更新于 1970-01-01 00:00:00)
license: MIT
Language: Swift .
🌃 How to prevent screen lock on my application?
最后发布版本: 2.0.1 ( 2021-05-17 23:13:18)
🌃 Insomnia
❤️ 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.
⚙ Modes:
-
.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).
👨💻 Usage:
1. Don't go to sleep, ever:
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .always)
}
2. Same but only when charging:
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .whenCharging)
}
3. Don't go to sleep if certain View Controller is alive:
final class SomeViewController: UIViewController {
private let insomnia = Insomnia(mode: .always)
}
4. Change mode:
insomnia.mode = .always
🤔 Rationale:
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?
👏 Credits:
Logo design by Artur Martynowski - check his dribble profile, he's really great!
最近版本更新:(数据更新于 1970-01-01 00:00:00)
2021-05-17 23:13:18 2.0.1
2019-04-06 05:15:33 2.0.0
2018-04-12 21:35:19 1.0.0
2016-12-18 06:16:31 0.9.5
2016-12-16 06:21:27 0.9.1
2016-12-13 20:11:11 0.9.0
主题(topics):
apple, ios, prevent-screen-lock, preventing-sleep, screen-locker, screen-off, swift-5
ochococo/Insomnia同语言 Swift最近更新仓库
2024-12-21 13:48:53 argmaxinc/WhisperKit
2024-12-19 06:06:30 stripe/stripe-ios
2024-12-16 23:43:56 wordpress-mobile/WordPress-iOS
2024-12-04 20:33:05 Artificial-Pancreas/iAPS
2024-12-03 10:12:09 utmapp/UTM
2024-11-25 23:11:48 Alamofire/Alamofire