当用户不允许在iOS中访问时,如何关闭imagePicker

时间:2016-06-28 10:16:13

标签: ios camera uiimagepickercontroller

当用户选择或捕获任何图像时,我正在检查我的应用程序上的相机和照片权限。 我正在使用此代码。

-(void)choosePhotoFromExistingImages
 {   
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
    if (status == ALAuthorizationStatusDenied  || status == ALAuthorizationStatusRestricted) {
        [APPDELEGATE showAlertViewForPhotos];
        //show alert for asking the user to give permission    
    }
    else{
        if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
        {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            controller.allowsEditing = YES;
            controller.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil] ;
            controller.delegate = self;
            [self presentViewController: controller animated: YES completion: nil];
        }
    }   
}

代码工作正常,但是当用户第一次选择不允许照片库时,它会显示黑屏,就像在相机中发生同样的事情。 我需要的是,当用户按下时不允许我可以检查用户是否取消了权限,这样我就可以关闭图像拾取器或相机。enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用ALAssetsLibrary authorizationStatus进行检查

How do I react to a user choosing "Don't Allow" when asking for permission to access Photos?