首先要添加加头文件
#import <Photos/Photos.h>
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请在iPhone的“设置-隐私-照片”选项中,允许XXX访问你的照片" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *photoesAction = [UIAlertAction actionWithTitle:@"好" style:0 handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"好");
}];
[alertController addAction:photoesAction];
[self presentViewController:alertController animated:YES completion:nil];
}else{
[self presentViewController:controller animated:YES completion:nil];
}