Reputation: 3329
I am building application using swift 2 targeting minimal iOS 8.
I need to present my application all the time without interrupted by device lock.
I am aware and currently using UIApplication.sharedApplication().idleTimerDisabled = true
to disable device locking.
The question is, is it possible (and how ?) to prevent device lock, but allow the screen to be dimmed (light off) ?
The goal is to save a bit more battery by turning off lcd light (without turning it off or lock device).
Thank you.
Upvotes: 16
Views: 6914
Reputation: 416
For my case we do not want the device to auto lock or dim. We have the snippet of code
UIApplication.sharedApplication().idleTimerDisabled = true
In Swift 4+
UIApplication.shared.isIdleTimerDisabled = true
In the view controllers that should not auto-lock or dim, yet our devices are still dimming but not auto-locking. For us this is annoying and a bug but for you it sounds like it's what you want. Although from other posts I have found:
It seems to be device specific, let me know if this helps.
Upvotes: 7
Reputation: 5450
You cannot prevent the dimming, but you can set the brightness during the app operation. You will still disable the idle timer, but modify the brightness manually.
UIApplication.sharedApplication().idleTimerDisabled = true
UIScreen.mainScreen().brightness = CGFloat(0.1)
Few notes regarding your question:
Swift 3
UIApplication.shared.isIdleTimerDisabled = true
Upvotes: 10