引言:
在iOS11的情况下, 相册权限是默认用户授权. 并且在设置->隐私->照片里, 并没有看到你的app有这个相册的读取和写入权限.
解决方法:
头文件
#import <Photos/PHPhotoLibrary.h>
#pragma mark ----相册
- (void)tapAlbum {
//----第一次不会进来
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) {
// 无权限 做一个友好的提示
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示"
message:@"请您设置允许该应用访问您的相机\n设置>隐私>相机"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alart show];
return;
}
//----每次都会走进来
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
NSLog(@"----------Authorized---------");
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//判断是否可以访问
return;
}
//创建对象
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
} else {
NSLog(@"--------Denied or Restricted-------");
//----为什么没有在这个里面进行权限判断,因为会项目会蹦。。。
}
}];
}
网友评论