How to Prevent the iPhone Screen from Dimming or Turning Off While My Application Is Running

How do I prevent the iPhone screen from dimming or turning off while my application is running?

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true

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

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

Keep iphone active while running program

This code will prevent your iPhone from going to sleep while your app is running

// avoid sleeping when this application is running
UIApplication *application = [UIApplication sharedApplication];
application.idleTimerDisabled = YES;
// Or simpler
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

Dim iPhone Screen, but don't let it sleep

I'm pretty sure there's nothing in the official SDK.

[(id)[UIApplication sharedApplication] setBacklightLevel:0.3f]; // or whatever value

works, but is of course undocumented. The recent experience with UIGetScreenImage indicates that perhaps the right strategy with useful but undocumented APIs is to use them and see what happens.

Failing that, has anybody ever measured if the phone's power consumption goes down if it's showing a black image, or does it not help unless you can turn down the backlight?

iPhone display screen lights not turning off automatically


[[UIApplication sharedApplication] setIdleTimerDisabled:NO];

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Are the two lines to enable/disable the dimming of the screen in an iOS app. Double check and see if your app has any of these.

Put this code into application didFinishLaunchingWithOptions: method.

iPhone: Can I programmatically disable auto turning off the display?

In AppDelegate add:

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions...

//Add this to your method
[UIApplication sharedApplication].idleTimerDisabled = YES;


Related Topics



Leave a reply



Submit