我正在使用UIImagePicker向用户呈现照片,以便用户可以选择要在我的应用程序中使用的图像。
我的问题是,当用户第一次打开图片选择器时,他们会看到一个提示:“我的应用程序想要访问你的照片”,其中有两个选项,“不允许”和“确定”。
我的要求是,当用户单击“不允许”时,图像选择器将被关闭。
有没有一种方法可以检测到用户选择了不允许?
目前,它给用户留下了一个丑陋的空白模式视图。如果用户再次打开图像选择器,他们会显示很好的苹果提供的消息,上面写着“此应用程序无法访问您的照片等。”
下面是我使用图像选择器的方法:
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imagePickerController animated:YES];发布于 2013-02-07 12:28:07
明白了!
if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusNotDetermined) {
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (*stop) {
// INSERT CODE TO PERFORM WHEN USER TAPS OK eg. :
return;
}
*stop = TRUE;
} failureBlock:^(NSError *error) {
// INSERT CODE TO PERFORM WHEN USER TAPS DONT ALLOW, eg. :
self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
}];
}发布于 2013-02-07 10:38:55
使用ALAssetsLibrary authorizationStatus。有一个特定的返回值指示您的应用程序已被拒绝。
在这里搜索该方法将显示一些用于正确处理各种授权状态的示例代码。
发布于 2015-04-14 00:44:54
我也遇到过类似的问题。你可以看看我下面的代码,如果它可以帮助任何将来可能有类似问题的人。我有一个IBAction,它可以帮助我加载图像。我用这个方法挣扎了4-5个小时。
(IBAction)loadImages:(id)sender {
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status == AVAuthorizationStatusAuthorized || status == AVAuthorizationStatusNotDetermined) {
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (*stop) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePicker animated:YES completion:^{
//TODO
}];
return;
}
*stop = TRUE;
} failureBlock:^(NSError *error) {
[imagePicker dismissViewControllerAnimated:YES completion:nil];
}];
}
if (status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted) {
UIAlertView *cameraAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Camera Access Required", nil) message:NSLocalizedString(@"Please allow us to access your camera roll in your device Settings.", nil) delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[cameraAlert show];
}
}https://stackoverflow.com/questions/14742578
复制相似问题