iOS 用户不允许访问时如何关闭 imagePicker
How to dismiss imagePicker when user don't allow access in iOS
当用户 select 或拍摄任何图像时,我正在检查我的应用程序的相机和照片权限。
我正在使用此代码。
-(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];
}
}
}
代码工作正常,但当用户第一次选择不允许照片库时,它显示黑屏,就像相机中发生的同样的事情。
我需要的是,当用户按下不允许时,我可以检查用户是否取消了权限,这样我就可以关闭图像选择器或相机。
您可以使用ALAssetsLibrary authorizationStatus
查看
How do I react to a user choosing "Don't Allow" when asking for permission to access Photos?
当用户 select 或拍摄任何图像时,我正在检查我的应用程序的相机和照片权限。 我正在使用此代码。
-(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];
}
}
}
代码工作正常,但当用户第一次选择不允许照片库时,它显示黑屏,就像相机中发生的同样的事情。
我需要的是,当用户按下不允许时,我可以检查用户是否取消了权限,这样我就可以关闭图像选择器或相机。
您可以使用ALAssetsLibrary authorizationStatus
查看
How do I react to a user choosing "Don't Allow" when asking for permission to access Photos?