【问题标题】:UIImagePickerController asks for access to photosUIImagePickerController 请求访问照片
【发布时间】:2014-10-12 08:04:30
【问题描述】:

即使我没有将照片保存在任何地方,但每当我在 didFinishPickingMediaWithInfo 函数中访问编辑后的图像时,iOS 都会要求我获得访问设备上照片的权限。

知道如何防止它请求许可。

添加 UIImagePickerController

- (IBAction)addPhotoButtonPressed:(id)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.showsCameraControls = YES;

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


}

didFinishPickingMediaWithInfo

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


    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *image;

   image = [info objectForKey:@"UIImagePickerControllerEditedImage"];


    if (image == nil)
        image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];


    NSData *imageData = UIImageJPEGRepresentation(image, 0.05f);
    _locationImage.image = [UIImage imageWithData:imageData];
    imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];

    }

【问题讨论】:

    标签: ios iphone ios8 uiimagepickercontroller


    【解决方案1】:

    我认为编写自己的编辑控件(虽然这并不难)没有任何害羞,然后你就可以完全控制了。

    UIImagePicker 是这样问的——我猜——因为它会临时保存原始图像,就好像它确实被保存了一样......

    【讨论】:

    • 您能否详细说明我是如何访问照片的,因为我没有直接访问或将任何内容保存到用户相册中?有没有我可以参考的文档链接。
    • 我试过了...如果你愿意,可以搜索其他编辑控件
    【解决方案2】:

    您必须知道,第一次访问照片库时,必须向用户请求许可

    http://www.macrumors.com/2012/06/14/apple-requires-user-permission-before-apps-can-access-personal-data-in-ios-6/

    你必须检查权限

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
    if(authStatus == AVAuthorizationStatusAuthorized) {
      // do your logic
    } else if(authStatus == AVAuthorizationStatusDenied){
      // denied
    } else if(authStatus == AVAuthorizationStatusRestricted){
      // restricted, normally won't happen
    } else if(authStatus == AVAuthorizationStatusNotDetermined){
      // not determined?!
      [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
        if(granted){
          NSLog(@"Granted access to %@", mediaType);
        } else {
          NSLog(@"Not granted access to %@", mediaType);
        }
      }];
    } else {
      // impossible, unknown authorization status
    }
    

    【讨论】:

    • 对不起,我正在调试它。当我这样做时,问题仍然存在。我需要它是可编辑的,但不向我显示照片权限访问。
    猜你喜欢
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多