Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: idleTimerDisabled = YES works only until ImagePicker was used

I have an iPad survey tool as an internal enterprise application. I prevent screen locking with setting [[UIApplication sharedApplication] setIdleTimerDisabled: YES]; at didFinishLaunchingWithOptions of the application delegate.

That works fine until I use the imagePicker to take an image. After that, the idleTimer is activated again. I have tried to disable it after the image was taken but that doesn't work.

Here I found the hint that setting the required device capabilities in the info.plist could help. But so far it didn't. I have just added all camera specific flags.

Any ideas?

Many thanks!

Marcus

like image 833
Marcus Franzen Avatar asked Apr 30 '14 15:04

Marcus Franzen


1 Answers

I was able to reset the UIApplication idleTimerDisabled like so:

- (void)resetIdleTimerDisabled
{
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:^{
        [self performSelector:@selector(resetIdleTimerDisabled) withObject:nil afterDelay:1.0];
    }];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:^{
        [self performSelector:@selector(resetIdleTimerDisabled) withObject:nil afterDelay:1.0];
    }];
}

What I suspect is happening is that internally UIImagePickerController sets UIApplication.idleTimerDisabled to YES to keep the camera from sleeping. When finished (after the delegate methods are called and apparently even after the animation completion block is executed), the UIImagePickerController sets UIApplication.idleTimerDisabled back to NO. Instead, it only should do this if the value was previously NO.

I filed a bug report with Apple. See UIImageViewControllerBug sample project.

like image 159
Jamie McDaniel Avatar answered Jan 03 '23 17:01

Jamie McDaniel