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.
Asked
Active
Viewed 9,158 times
1
-
3Your 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 Answers
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
-
Yes, it is working. I've checked the sample application you sent me on chat and it does the same as I wrote for you. – Infinite Possibilities Sep 06 '11 at 09:33
-
i put NSTimer in didLoad and call the method disabledIdleTimer after every 2 mints bt still not working :( – Aadil Sep 06 '11 at 09:38
-
-
then you didn't got the idea why the lock is happening... please think a bit on it – Infinite Possibilities Sep 06 '11 at 09:44
-
Hi, i have implement this functionality, but its not working, can anyone help me ,how we can auto lock screen after a time interval....thanks looking your answers...... – ravinder521986 Jun 06 '13 at 06:55