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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With