views:

1640

answers:

3

Hi, how to set iPhone device to stay active ( to not lock ) while my app is running ? Any idea

+10  A: 

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

// avoid sleeping when this application is running
    application.idleTimerDisabled = YES;
wulfovitch
+19  A: 

I'm not sure if this prevents the device from locking, but you can prevent the screen from dimming with the UIApplication's idleTimerDisabled property:

[UIApplication sharedApplication].idleTimerDisabled = YES;

From the documentation:

Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.

Adam Rosenfield
A: 

The idleTimerDisabled method does not work on iPhone 3.0 sometimes

It's a reported bug, see http://www.iphonedevsdk.com/forum/iphone-sdk-development-iphone-os-3-0/20420-idletimerdisabled-not-working.html