iOS判断访问相册权限

2022-03-28  本文已影响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];
                    });
                }
            });
        }];
上一篇 下一篇

猜你喜欢

热点阅读