Insomnia 2.0.0

Insomnia 2.0.0

测试已测试
语言编程语言 SwiftSwift
许可证 MIT
发布上次发布2019年4月
SPM支持 SPM

Oktawian Chojnacki 维护。



Insomnia 2.0.0

  • Oktawian Chojnacki

🌃Insomnia

Insomnia Logo

Swift4.1 Coverage 100% Version License Platform Documentation

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 - 无任何更改(禁用功能)。
  • .always - 你的 iOS 设备将永远不会超时并进入睡眠状态。
  • .whenCharging - 设备将保持活跃,直到连接到充电器。

重要:如果 Insomnia 实例被销毁,其功能将自动禁用,设备将正常行为(超时、禁用屏幕和锁定)。

👨‍💻用法

1. 永不进入睡眠状态

final class AppDelegate: UIApplicationDelegate {
	private let insomnia = Insomnia(mode: .always)
}

2. 与之上相同,但仅在充电时

final class AppDelegate: UIApplicationDelegate {
	private let insomnia = Insomnia(mode: .whenCharging)
}

3. 如果某个视图控制器是活跃的,不要去睡觉

final class SomeViewController: UIViewController {
	private let insomnia = Insomnia(mode: .always)
}

4. 改变模式

insomnia.mode = .always

🤔理由

太简单的答案是

UIApplication.shared.isIdleTimerDisabled = true

这个解决方案的问题是,当不再需要时,你必须记得将这个全局变量更改到false。如果你想只在设备充电时激活它呢?

👏鸣谢

标志设计由Artur Martynowski - 查看他的dribble个人资料,他真的很棒!