Swift, disable device lock, but enable lcd light off (dull screen)

I am building an application using a fast 2-oriented minimal iOS 8.

I need to constantly submit the application, not interrupted by locking the device.

I know and am currently using UIApplication.sharedApplication().idleTimerDisabled = true to disable device lock.

The question is, is it possible (and how?) To prevent the device from locking, but to let the screen fade (the light is off)?

The goal is to save a little more battery by turning off the lcd light (without turning it off or by locking the device).

Thanks.

+7
ios8 swift
source share
2 answers

In my case, we do not want the device to automatically lock or dull. We have a code snippet

 UIApplication.sharedApplication().idleTimerDisabled = true 

In controllers, views that should not automatically lock or fade, but our devices are still obscured, but not auto-locked. For us, this is annoying and error, but for you it sounds the way you want. Although from other posts I found:

  • iPhone - the phone goes to sleep even if idleTimerDisabled - YES
  • idleTimerDisabled does not work with iPhone 3.0

This device seems to be specific, let me know if that helps.

+4
source share

You cannot prevent dimming, but you can set the brightness while the application is running. You still turn off the idle timer, but change the brightness manually.

 UIApplication.sharedApplication().idleTimerDisabled = true UIScreen.mainScreen().brightness = CGFloat(0.1) 

A few notes regarding your question:

  • Luminance values ​​are between 0.0 and 1.0
  • If the application really started in the background (the idle timer is turned on), the brightness value will return to user settings
  • Sets the brightness of the display.

Swift 3

  UIApplication.shared.isIdleTimerDisabled = true 
+2
source share

All Articles