3

Is there a way to 'force' the user to have auto-lock (and maybe passcode lock) on while the application is running (for security reasons mainly)? If we can't set them programmatically, can we at least check to see if they are set?

Thanks, Mihai

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Mihai Fonoage
  • 478
  • 2
  • 8
  • 23
  • Similar to: http://stackoverflow.com/questions/1023265/iphone-delaying-but-not-disabling-iphone-auto-lock ..I'm unsure about turning it on if they user has it disabled in settings, I've never tried it that way. – iwasrobbed Jul 23 '10 at 14:30
  • That post, and other that I found, is not helpful unfortunately. Most deal with disabling the auto-lock, even if just temporarily, while I need it enabled. – Mihai Fonoage Jul 23 '10 at 14:37
  • Enabling/Disabling is the difference between a `NO` and a `YES` for example.. `[[UIApplication sharedApplication] setIdleTimerDisabled: NO];` or `[[UIApplication sharedApplication] setIdleTimerDisabled: YES];` ..but like I said, I haven't tested to see if this overrides what the user sets in the `Settings` app. – iwasrobbed Jul 23 '10 at 16:41
  • 1
    I tested it on my iPad. I used "NSLog(@"idleTimerDisabled: %@", [ UIApplication sharedApplication ].idleTimerDisabled ? @"YES" : @"NO");" inside didFinishLaunchingWithOptions, and changed the Auto-Lock option from the Settings menu to "Never" and then to "2 Minutes", but the value returned is always NO, which is what I wanted it to be, but it does not reflect the actual settings of the Auto-Lock on the device itself. – Mihai Fonoage Jul 23 '10 at 16:58

2 Answers2

0
if ([UIApplication sharedApplication].idleTimerDisabled == YES) {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Please enable auto-lock"...];
    [alert show];
    [alert release];
} else {
    /* some code */
}

The above snippet will check to see if the idle timer is disabled. If it is, it will tell the user to enable it via a UIAlertView.

esqew
  • 42,425
  • 27
  • 92
  • 132
  • idleTimerDisabled is always NO on iPad, no matter if Auto-Lock is set or not. – Mihai Fonoage Jul 23 '10 at 14:59
  • Really? I haven't seen anything saying so. Wouldn't you think Apple would document that? – esqew Jul 23 '10 at 16:12
  • 1
    I tested it on my iPad. I used "NSLog(@"idleTimerDisabled: %@", [ UIApplication sharedApplication ].idleTimerDisabled ? @"YES" : @"NO");" inside didFinishLaunchingWithOptions, and changed the Auto-Lock option from the Settings menu to "Never" and then to "2 Minutes". – Mihai Fonoage Jul 23 '10 at 16:35
  • Mihai is right, `idleTimerDisabled` is NOT related to how user set auto lock. You will forever get this: `(lldb) p (int)[[UIApplication sharedApplication] isIdleTimerDisabled] (int) $0 = 0` – Philip007 Feb 14 '13 at 20:10
0

YOu can use a Session handler class which inherits from UIApplication and fix a timer.. Thats very easy and fully customizable.

Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62