Auto Lock iPhone programmatically
Asked Answered
U

1

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.

Useless answered 6/9, 2011 at 7:44 Comment(3)
Your link describes how to prevent auto-lock. You can't lock the device programmatically.Ives
@fichek Have you saw Alarm apps on App Store ??? All of them have that functionality to auto lock Device.Useless
@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.Hazel
H
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.

Hazel answered 6/9, 2011 at 9:26 Comment(5)
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.Hazel
i put NSTimer in didLoad and call the method disabledIdleTimer after every 2 mints bt still not working :(Useless
don't call it after every 2 minutes... :|Hazel
then you didn't got the idea why the lock is happening... please think a bit on itHazel
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......Aboriginal

© 2022 - 2024 — McMap. All rights reserved.