3

I want to disable the auto lock on my iOS4.3.3 program. I found on the web the same answer several times for this and working for xcode3 but I cant find it to work with mine.. help pls? thks

StinkyCat
  • 1,236
  • 1
  • 17
  • 31

2 Answers2

8

This should work on iOS 4.3.3. If not then you're doing something wrong:

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Robin Summerhill
  • 13,695
  • 3
  • 41
  • 37
  • hum.. the other version used the "." and wasn't accepted in my xcode, now this version is accepted.. one last question: i have several views, where exactly will i put it? Thks! – StinkyCat Sep 28 '11 at 13:30
  • 2
    It's a global setting so you can put it where it is most appropriate for your app. If you want to disable locking for the entire time the app is running then you could set it in your app delegate's appDidFinishLaunching/appDidBecomeActive methods and turn it off in appDidEnterBackground. – Robin Summerhill Sep 28 '11 at 15:38
  • 1
    Setting `idleTimerDisabled` in `appDidEnterBackground:` no longer seems to work with 5.1.1. – Kent Aug 26 '12 at 07:02
3

I did it in a ViewController like this.

-(void) viewDidAppear:(BOOL)animated
{
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}

-(void) viewDidDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
orkoden
  • 18,946
  • 4
  • 59
  • 50
  • 1
    Just a reminder, don't forget the [super viewDidAppear:] when copy and paste this code snippet. – Jakehao Nov 13 '15 at 02:53