iOS: 如何link iPhone 设置PHPhotoLibrary权限

iOS: how to link iPhone settings to PHPhotoLibrary permission

我正在尝试实现一个访问相机胶卷的应用程序。以下是我检查权限的方式:

-(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:

但我还没搞清楚link 怎么切换到权限。你们知道我如何 link 切换到相机胶卷权限吗?

非常感谢你的帮助。

你可以试试这个代码:

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