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

Ram*_*lya 7 uiimagepickercontroller ios ios8

我正在使用默认的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];
}
Run Code Online (Sandbox Code Playgroud)

和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];
}
Run Code Online (Sandbox Code Playgroud)

崩溃消息:

*** This application is not allowed to access Photo data.
Run Code Online (Sandbox Code Playgroud)

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

小智 2

使用 Assets Framework 测试是否允许您的应用程序访问照片数据。

  ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

  if(status==ALAuthorizationStatusAuthorized) {
        ..your code...
  }
Run Code Online (Sandbox Code Playgroud)