{"id":17968668,"url":"https://github.com/ochococo/insomnia","last_synced_at":"2025-06-30T13:40:55.306Z","repository":{"id":51289045,"uuid":"75602010","full_name":"ochococo/Insomnia","owner":"ochococo","description":"🌃 How to prevent screen lock on my application?","archived":false,"fork":false,"pushed_at":"2021-05-17T15:43:33.000Z","size":228,"stargazers_count":108,"open_issues_count":2,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-20T01:06:58.739Z","etag":null,"topics":["apple","ios","prevent-screen-lock","preventing-sleep","screen-locker","screen-off","swift-5"],"latest_commit_sha":null,"homepage":"http://cocoadocs.org/docsets/Insomnia","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ochococo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"ochococo"}},"created_at":"2016-12-05T07:57:55.000Z","updated_at":"2024-11-13T19:26:54.000Z","dependencies_parsed_at":"2022-08-12T23:10:12.772Z","dependency_job_id":null,"html_url":"https://github.com/ochococo/Insomnia","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ochococo%2FInsomnia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ochococo%2FInsomnia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ochococo%2FInsomnia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ochococo%2FInsomnia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ochococo","download_url":"https://codeload.github.com/ochococo/Insomnia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245444345,"owners_count":20616364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","ios","prevent-screen-lock","preventing-sleep","screen-locker","screen-off","swift-5"],"created_at":"2024-10-29T14:41:12.839Z","updated_at":"2025-03-25T10:32:28.852Z","avatar_url":"https://github.com/ochococo.png","language":"Swift","funding_links":["https://github.com/sponsors/ochococo"],"categories":[],"sub_categories":[],"readme":"🌃 Insomnia\n===========\n\n![Insomnia Logo](Insomnia.jpg)\n\n![Swift4.1](https://img.shields.io/badge/%20in-swift%205.0-orange.svg)\n![Coverage 100%](https://img.shields.io/badge/coverage-100%25-green.svg)\n[![Version](https://img.shields.io/cocoapods/v/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)\n[![License](https://img.shields.io/cocoapods/l/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)\n[![Platform](https://img.shields.io/cocoapods/p/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)\n[![Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)\n[![Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/Insomnia.svg?style=flat)](http://cocoadocs.org/docsets/Insomnia)\n[简体中文](https://github.com/CharlotteFallices/Insomnia/blob/master/README_zh.md)\n\n❤️ Please consider supporting my work, [become my Sponsor!](https://github.com/sponsors/ochococo) 🙏\n\nMicro library to answer to questions like:\n\n- How to prevent screen lock on my application?\n- How can I prevent the display on an iOS device from dimming and turning off?\n- How do I prevent the iPhone screen from dimming or turning off while certain ViewController is presented?\n\nWell... Sometimes you want your iPhone to stay active a little bit longer is it an import or just game interface.\n\nThis project aims to simplify the code and give you a well tested solution.\n\n⚙ Modes:\n========\n\n- `.disabled` - Nothing will change (disabled functionality).\n- `.always` - Your iOS device will never timeout and go to sleep.\n- `.whenCharging` - Device will stay active as long as it's connected to charger.\n\n**Important:** If Insomnia instance is deallocated, it's functionality is automatically disabled and device will behave nominally (timeout, disable screen and lock).\n\n\n👨‍💻 Usage:\n=========\n\n## 1. Don't go to sleep, ever:\n\n```swift\nfinal class AppDelegate: UIApplicationDelegate {\n\tprivate let insomnia = Insomnia(mode: .always)\n}\n\n```\n\n## 2. Same but only when charging:\n\n```swift\nfinal class AppDelegate: UIApplicationDelegate {\n\tprivate let insomnia = Insomnia(mode: .whenCharging)\n}\n```\n\n## 3. Don't go to sleep if certain View Controller is alive:\n\n```swift\nfinal class SomeViewController: UIViewController {\n\tprivate let insomnia = Insomnia(mode: .always)\n}\n```\n\n## 4. Change mode:\n\n```swift\ninsomnia.mode = .always\n```\n\n🤔 Rationale:\n=============\n\nThe too simple answer is:\n\n```swift\nUIApplication.shared.isIdleTimerDisabled = true\n```\n\nThe problem with this solution is that you have to remember to change this global variable to `false` when it's no longer needed. \nWhat if you want to activate it only when your device is on charger? \n\n👏 Credits:\n===========\n\n\nLogo design by [Artur Martynowski](https://dribbble.com/artur-martynowski) - check his dribble profile, he's really great!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fochococo%2Finsomnia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fochococo%2Finsomnia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fochococo%2Finsomnia/lists"}