ios - iOS 7 中的应用程序崩溃

标签 ios ios7 uiimagepickercontroller

当我在 iPhone 上使用 UIImagePicker 时应用程序崩溃,但仅在 iOS 7 上。 我使用以下代码行

    picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;
    picker.allowsEditing = YES;

    if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        //[self showAlertViewWithTitle:@"Sorry" message:@"Your Device Don't Have Camera"];
    }

    [self presentViewController:picker animated:YES completion:nil];

}

该应用程序在 iOS 6 上运行,而不是在 iOS 7 上运行。 我是这个网站的新手,请帮忙。

最佳答案

UIImagePickerController 仅在 iPhone 中以 Potratin 模式呈现。我在您的代码中发现了一个错误,您正在使用 picker.sourceType = UIImagePickerControllerSourceTypePhotoLibraryisCameraDeviceAvailable 是错误的:-

你应该这样编码:-

if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                 [self presentViewController:picker animated:YES completion:nil];
    } else {
         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                 [self presentViewController:picker animated:YES completion:nil];       
    }

并在您的 ViewController 中将 shouldAutorotate 更改为 NO 而不是 YES

关于ios - iOS 7 中的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19487478/

相关文章:

ios - 启动使用 Simperium 的应用程序时 objectFromJSONString 崩溃

objective-c - 如何在 iOS 应用程序中捕获用户的手写签名

ios - 拍摄照片并将其保存到相机胶卷

ios - 将照片库中的图像导入 xcode 中的应用程序

ios - 欧拉角 Y 值受 X 和 Z 值的影响——如何将它们归零以获得 "truthful"y 值?

ios - React native 错误 AppRegistry 未定义?

ios - UITableView 单元格选择颜色?

ios7 - UIAutomation dragInsideWithOptions对iOS 7模拟器无效

ios - 具有不同项目高度的自下而上的 UITableView 滚动到结束

iphone - UIImagePickerController的didFinishPickingMediaWithInfo太慢,我可以添加progressHUD/indicator吗?