I'm diving into iOS development and am building my own alarm clock app to become familiar with platform and SDK. I've noticed some alarm clock apps in the app store keep the screen from dimming and/or turning off when their app is running. How is this implemented?
Asked
Active
Viewed 3.8k times
1 Answers
194
Add this line of code on your application delegate:
Objective-C:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Swift 2:
UIApplication.sharedApplication().idleTimerDisabled = true
Swift 3, 4 & 5:
UIApplication.shared.isIdleTimerDisabled = true

PhillipJacobs
- 2,337
- 1
- 16
- 32

Iñigo Beitia
- 6,303
- 4
- 40
- 46
-
13You can use this in swift as UIApplication.sharedApplication().idleTimerDisabled = true – Vettiyanakan Mar 27 '15 at 07:01
-
not run when app add view UIImagePickerController, app will auto dim when remove subview – vualoaithu Nov 15 '17 at 04:12