简体   繁体   中英

UIImagePickerController with UIImagePickerControllerSourceTypeCamera crash

I have the following code:

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Camera is not available." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
    return;
}

UIImagePickerController * cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setSourceType:UIImagePickerControllerSourceTypeCamera];
[cameraUI setMediaTypes:@[(NSString*)kUTTypeMovie]];
[cameraUI setAllowsEditing:NO];
[cameraUI setDelegate:self];

[navigationController presentViewController:cameraUI animated:YES completion:^{

    NSLog(@"completed present camera controller");

}];

and I get this crash:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

It happens on iOS7, iOS8, iPad & iPhone. If I comment the "present" method, it doesn't crash, but after commenting each line one by one, I found that this is the only one that crashes my app (without it the "present" works and it takes me to library):

[cameraUI setSourceType:UIImagePickerControllerSourceTypeCamera];

I'm really out of ideas here. Can anyone help me out?

I found the problem, maybe someone will encounter the same problem sometime... I needed a property set on all the buttons inside my app, so I created a UIButton category in which I had overridden -initWithFrame: , and this caused the crash. Apparently something needed to happen there for the camera UI that wasn't happening anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM