美文网首页
iOS判断访问相册权限

iOS判断访问相册权限

作者: 黎先生_ | 来源:发表于2022-03-28 17:36 被阅读0次
#import<Photos/Photos.h>
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (status == PHAuthorizationStatusAuthorized) {//相册权限已开启
                    UIViewController *VC = [[UIViewController alloc] init];
                    [self.navigationController pushViewController:gong animated:YES];
                } else {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"相册权限未开启,请开启相册权限" preferredStyle:UIAlertControllerStyleAlert];
                        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
                        }];
                        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                        }];
                        [alertController addAction:confirm];
                        [alertController addAction:cancel];
                        [self presentViewController:alertController animated:YES completion:nil];
                    });
                }
            });
        }];

相关文章

网友评论

      本文标题:iOS判断访问相册权限

      本文链接:https://www.haomeiwen.com/subject/jdgpjrtx.html