【问题标题】:iOS: how to link iPhone settings to PHPhotoLibrary permissioniOS:如何将 iPhone 设置链接到 PHPhotoLibrary 权限
【发布时间】: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


【解决方案1】:

你可以试试这个代码:

if (status == PHAuthorizationStatusNotDetermined) {
        // Access has not been determined.
        [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
            if (status == PHAuthorizationStatusAuthorized) {
                // do something
            }else {
                // Access has been denied.
            }
        }];
    } 

【讨论】:

  • 这很好用。但是如果用户想要将状态从“不允许”更改为“允许”。需要通过设置来完成。如何将设置链接到实施?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 2011-09-25
相关资源
最近更新 更多