1、引入头文件#import<Photos/Photos.h>
#pragma mark-- 检测是否开启相册权限
-(void)photoPower{
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == PHAuthorizationStatusAuthorized) {//开启
//开启后的操作
}else{
//注,这里一定要回归的主线程操作UI
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"相册权限未设置,请开启相册权限"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertControlleraddAction:cancelAction];
[alertControlleraddAction:okAction];
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];
});
}
});
}];
}
网友评论