Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ochococo/insomnia
đ How to prevent screen lock on my application?
https://github.com/ochococo/insomnia
apple ios prevent-screen-lock preventing-sleep screen-locker screen-off swift-5
Last synced: about 2 months ago
JSON representation
đ How to prevent screen lock on my application?
- Host: GitHub
- URL: https://github.com/ochococo/insomnia
- Owner: ochococo
- License: mit
- Created: 2016-12-05T07:57:55.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T15:43:33.000Z (over 3 years ago)
- Last Synced: 2024-10-14T06:16:13.987Z (2 months ago)
- Topics: apple, ios, prevent-screen-lock, preventing-sleep, screen-locker, screen-off, swift-5
- Language: Swift
- Homepage: http://cocoadocs.org/docsets/Insomnia
- Size: 223 KB
- Stars: 107
- Watchers: 4
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
đ Insomnia
===========![Insomnia Logo](Insomnia.jpg)
![Swift4.1](https://img.shields.io/badge/%20in-swift%205.0-orange.svg)
![Coverage 100%](https://img.shields.io/badge/coverage-100%25-green.svg)
[![Version](https://img.shields.io/cocoapods/v/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)
[![License](https://img.shields.io/cocoapods/l/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)
[![Platform](https://img.shields.io/cocoapods/p/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)
[![Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)
[![Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)
[įŽäŊä¸æ](https://github.com/CharlotteFallices/Insomnia/blob/master/README_zh.md)â¤ī¸ Please consider supporting my work, [become my Sponsor!](https://github.com/sponsors/ochococo) đ
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:
```swift
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .always)
}```
## 2. Same but only when charging:
```swift
final class AppDelegate: UIApplicationDelegate {
private let insomnia = Insomnia(mode: .whenCharging)
}
```## 3. Don't go to sleep if certain View Controller is alive:
```swift
final class SomeViewController: UIViewController {
private let insomnia = Insomnia(mode: .always)
}
```## 4. Change mode:
```swift
insomnia.mode = .always
```đ¤ Rationale:
=============The too simple answer is:
```swift
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](https://dribbble.com/artur-martynowski) - check his dribble profile, he's really great!