当用户在移动和放弃之后拒绝对照片的许可时,iOS应用程序崩溃在UIImagePickerController中缩放

时间:2015-01-12 23:10:31

标签: ios ios8 uiimagepickercontroller

我正在使用默认的UIImagePickerController,并将allowsEditing设置为YES来拍摄照片。当用户移动并缩放照片时,操作系统会要求访问照片'。 如果用户拒绝访问,应用程序将崩溃。

- (void)openCamera
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.editing = YES;
    imagePickerController.allowsEditing = YES;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.delegate = self;
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

UIImagePickerControllerDelegate方法就像

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *image = info[UIImagePickerControllerEditedImage];
    if (!image) {
        image = info[UIImagePickerControllerOriginalImage];
    }

    self.profileImage = image;

    [picker dismissViewControllerAnimated:YES completion:nil];
}

崩溃讯息:

*** This application is not allowed to access Photo data.

我想知道为什么它应该首先要求访问照片。 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

使用资产框架测试您的应用是否可以访问照片数据。

  ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

  if(status==ALAuthorizationStatusAuthorized) {
        ..your code...
  }