Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent the display on an iOS device from dimming and turning off? [duplicate]

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?

like image 662
BeachRunnerFred Avatar asked Aug 08 '10 21:08

BeachRunnerFred


People also ask

Why does my screen keep dimming IOS?

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.


1 Answers

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 
like image 155
Iñigo Beitia Avatar answered Sep 21 '22 20:09

Iñigo Beitia