带有UIImagePickerControllerSourceTypeCamera的UIImagePickerController在ios7中崩溃EXC_BAD_ACCESS

时间:2013-11-23 13:42:10

标签: ios objective-c ios7 uiimagepickercontroller exc-bad-access

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];

此代码使ios7设备上的EXC_BAD_ACCESS崩溃。 在iOS6上 - 一切正常,UIImagePickerControllerSourceTypePhotoLibrary工作正常。

1 个答案:

答案 0 :(得分:7)

使用相机

if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeCamera]) {
    UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.mediaTypes = [NSArray arrayWithObjects:
                                        (NSString *) kUTTypeImage,
                                        (NSString *) kUTTypeMovie, nil];
    [self presentViewController:imagePickerController animated:YES completion:nil];    }