I'm having an issue presenting the UIImagePickerController on iOS 7 devices. I use the following code to present the image picker.
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
cameraUI.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
cameraUI.delegate = self;
[[self presentViewController:cameraUI animated:YES completion:NULL];
After the call to presentViewController, the application crashes due to an exec bad access. The console reports the following exceptions.
[SBSAccelerometer valueRestriction]: unrecognized selector sent to instance 0x1650e360
[__NSCFNumber valueRestriction]: unrecognized selector sent to instance 0x146d0e70
I enabled zombies to see if an object is getting deallocated prematurely. Zombies reports the following exceptions:
[NSISRestrictedToNonNegativeVariable retain]: message sent to deallocated instance 0x156f0010
Any thoughts?
EDIT
Here is the stack trace I receive with zombies enabled:
This is a bug in iOS 7 on iPad. It appears the solution for now is to request permission to photos before opening the UIPopoverControl. Here is how I implemented my solution:
**// Photo Library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
void(^blk)() = ^() {
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (NIIsPad()) {
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromBarButtonItem:self.popoverAnchor permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self.navigationController presentModalViewController:picker animated:YES];
}
};
// Make sure we have permission, otherwise request it first
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAuthorizationStatus authStatus;
if (IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
authStatus = [ALAssetsLibrary authorizationStatus];
else
authStatus = ALAuthorizationStatusAuthorized;
if (authStatus == ALAuthorizationStatusAuthorized) {
blk();
} else if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
[[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
} else if (authStatus == ALAuthorizationStatusNotDetermined) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Catch the final iteration, ignore the rest
if (group == nil)
dispatch_async(dispatch_get_main_queue(), ^{
blk();
});
*stop = YES;
} failureBlock:^(NSError *error) {
// failure :(
dispatch_async(dispatch_get_main_queue(), ^{
[[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
});
}];
}
}**
Don't forget to add AssetsLibrary.framework to your 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