我正在检查相机卷的权限:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
}
}];
}
}它运行良好,但问题是,如果用户选择“不允许”,并希望切换到“允许”。
用户如何将权限切换到相机卷?
发布于 2017-05-19 14:23:36
你可以要求你的用户打开权限,如果他们说“是的,我想打开这个权限”,那么你可以使用NSURL将它们直接传输到你的应用程序的首选项中,他们也可以通过单击状态栏左边的后退按钮返回到你的应用程序。
这里是将用户传输到应用程序首选项的代码:
NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];这里是我在iOS10 iPhone6s:中测试的完整代码
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status != PHAuthorizationStatusNotDetermined) {
// Access has not been determined.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
// do something
}else {
// Access has been denied.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Need Photo Permission"
message:@"Using this app need photo permission, do you want to turn on it?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSURL *settingsUrl = [[NSURL alloc] initWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsUrl];
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
}];
[alert addAction:yesAction];
[alert addAction:noAction];
[self presentViewController:alert animated:YES completion:nil];
}
}];
}
}https://stackoverflow.com/questions/44030505
复制相似问题