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?
Why Your iPhone Keeps Dimming. Most of the time, your iPhone keeps dimming because Auto-Brightness is turned on. Auto-Brightness is a feature that automatically adjusts the brightness of your iPhone screen depending on the lighting conditions around you.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With