[英]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. 它发生在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):
如果我注释“ present”方法,它不会崩溃,但是在逐行注释每一行之后,我发现这是唯一使我的应用程序崩溃的方法(没有它,“ present”方法有效,它将我带到库中) ):
[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. 我发现了问题,也许有人有时会遇到相同的问题...我需要在我的应用程序内的所有按钮上设置一个属性,因此我创建了一个
UIButton
类别,其中我覆盖了-initWithFrame:
这导致崩溃。 Apparently something needed to happen there for the camera UI that wasn't happening anymore. 显然,相机UI需要在那里发生的事情不再发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.