【发布时间】:2017-10-16 05:41:33
【问题描述】:
我正在尝试实现一个访问相机胶卷的应用。以下是我检查权限的方式:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusAuthorized) {
NSString *accessDescription = [[NSBundle mainBundle]
objectForInfoDictionaryKey:@"NSPhotoLibraryUsageDescription"];
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:accessDescription
message:@"To give permissions tap on 'Change Settings' button"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
[alertController addAction:cancelAction];
UIAlertAction *settingsAction = [UIAlertAction
actionWithTitle:@"Change Settings"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
options:@{}
completionHandler:nil];
}];
[alertController addAction:settingsAction];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController
animated:YES
completion:nil];
}
}
我也添加了 Settings.bundle:
但我还没有弄清楚如何将切换开关链接到权限。你们中的任何人都知道如何将切换开关链接到相机胶卷权限吗?
非常感谢您的帮助。
【问题讨论】:
-
您不自行管理此权限请求;当您访问照片库时,iOS 会为您执行此操作。例如stackoverflow.com/questions/13572220/…
-
@Paulw11,在同一页面中 stackoverflow.com/questions/13572220/… 正在将用户发送到设置
-
是的,这会打开你的设置,但你不能把你自己的开关放在那里;一旦您请求权限,iOS 就会执行此操作。您链接到的代码使您可以在用户拒绝时请求用户授予权限(iOS 只会询问用户一次,之后它会使用他们设置的权限)
标签: ios objective-c iphone uiimagepickercontroller xcode8