iOS应用程序在用户在UIImagePickerController中的“移动和缩放”后拒绝访问照片权限时崩溃。

7

我正在使用默认的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.

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

已经在TweetBot应用程序中测试了该案例。那里也崩溃了。似乎是操作系统的问题。 - Ramsundar Shandilya
我建议在打开相机之前检查“照片”权限,因为您允许编辑,这似乎需要访问照片。 - rmaddy
你有找到任何解决方案吗? - Gagan Joshi
1个回答

2
使用Assets Framework来测试您的应用程序是否被允许访问照片数据。
  ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接