1

I am working on an alarm app, which needs to auto-lock the device after a particular time period, since most of the clock applications in the App Store have that feature.

jscs
  • 63,694
  • 13
  • 151
  • 195
Aadil
  • 713
  • 2
  • 12
  • 30
  • 3
    Your link describes how to **prevent** auto-lock. You can't lock the device programmatically. – Filip Radelic Sep 06 '11 at 08:39
  • @fichek Have you saw Alarm apps on App Store ??? All of them have that functionality to auto lock Device. – Aadil Sep 06 '11 at 08:54
  • @fichek is true, you can't set programatically your phone to auto lock... the link you added neither does it, it uses a trick, which you can't understand, so go and RTFM before you add -1 to anybody. – Infinite Possibilities Sep 06 '11 at 10:24

1 Answers1

1

If you would like to lock the phone after 5 minutes then do the following:
set this: [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
and also set a timer: [NSTimer scheduledTimerWithTimeInterval:240 target:self selector:@selector(disableIdleTimer) userInfo:nil repeats:NO];
And in the disableIdleTimer method you will set this: [[UIApplication sharedApplication] setIdleTimerDisabled:NO];

This will work with the following condition: the iPhone's autolock function is set to the minimum (1 minute).

As I see in the moment, there is no better method.

Infinite Possibilities
  • 7,415
  • 13
  • 55
  • 118