无法处理 NSPhotoLibraryAddUsageDescription 的权限
Posted
技术标签:
【中文标题】无法处理 NSPhotoLibraryAddUsageDescription 的权限【英文标题】:Not able to handle permission for NSPhotoLibraryAddUsageDescription 【发布时间】:2018-03-02 13:51:15 【问题描述】:我正在使用uiactivityviewcontroller
;其中有一个将照片保存到设备的选项。
所以我添加了NSPhotoLibraryAddUsageDescription
密钥以获得许可,
但无法处理权限,一旦用户点击Don't allow
,当再次点击相同选项保存照片时没有任何反应;
我看到了这个链接:Determine if the access to photo library is set or not - phphotoLibrary
但这并没有帮助;在这两种情况下(允许或不允许)它都返回PHAuthorizationStatusNotDetermined
我已经尝试过PHPhotoLibrary.requestAuthorization
。它适用于读取和写入权限。我只想添加照片;所以只需要写权限。
有没有办法处理这个权限?
【问题讨论】:
您能否发布您的代码请求访问照片库以及保存您的照片的代码 当我使用 UIActivityViewController 时,它会自动完成;我只需要在 info.plist 文件中添加键 'NSPhotoLibraryAddUsageDescription'。保存选项由控制器 @Spads 自动给出 【参考方案1】:我也遇到了同样的问题,这是我的解决方案,我是怎么处理的。
NSArray *dataToShare= @[@"Test",@"",[self contentURLofCurrentPreviewItem]];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[self presentViewController:activityViewController animated:YES completion:nil];
else
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
activityViewController.popoverPresentationController.sourceView = view;
[popup presentPopoverFromRect:view.frame
inView:view.superview
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined)
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status)
if (status == PHAuthorizationStatusDenied)
[self showAlert];
];
[activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError)
if ([activityType isEqualToString:@"com.apple.UIKit.activity.SaveToCameraRoll"])
if (![self getaccess])
[self showAlert];
];
//检查照片库的访问权限
-(bool)getaccess
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized)
return YES;
// Access has been granted.
else if (status == PHAuthorizationStatusDenied)
return NO;
// Access has been denied.
else if (status == PHAuthorizationStatusRestricted)
return NO;
// Restricted access - normally won't happen.
return NO;
-(void)showAlert
NSString *message = @"Save Image option required access of Photo Library. Please allow Photos app access for Your App in the Settings application.";
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"Your App", nil)
message:NSLocalizedString(message,nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Go To Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
];
[alert addAction:settingsAction];
UIAlertAction *Cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
//do something when click button
];
[alert addAction:Cancel];
[self presentViewController:alert animated:YES completion:nil];
【讨论】:
以上是关于无法处理 NSPhotoLibraryAddUsageDescription 的权限的主要内容,如果未能解决你的问题,请参考以下文章
Kotlin Spring Boot 注解处理“无法解析配置处理”
无法处理 NSPhotoLibraryAddUsageDescription 的权限
无法处理 authenticateForTransportDiscovery \ validateMetadata 请求[关闭]