83

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?

0

1 Answer 1

197

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
2
  • 13
    You can use this in swift as UIApplication.sharedApplication().idleTimerDisabled = true Mar 27, 2015 at 7:01
  • not run when app add view UIImagePickerController, app will auto dim when remove subview
    – vualoaithu
    Nov 15, 2017 at 4:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.