前段时间更新iOS11之后,相册部分,访问相册默认是放开权限的,但是在保存相册的时候,判断权限不再能够满足项目需求。在一个偶然机会翻阅文档,找到了解决方案,期望对大家有所帮助,上代码:
iOS11以前
#pragma mark - 访问相册
+ (BOOL)CanPhotoLibary{
PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
if (authStatus == PHAuthorizationStatusRestricted|| authStatus == PHAuthorizationStatusDenied) {
returnNO;
}else{
returnYES;
}
}
iOS11以后:
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusNotDetermined || status == PHAuthorizationStatusAuthorized) {
UIImageWriteToSavedPhotosAlbum(_HeadImg,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);//保存图片到相册
}else{
//[JLHelperManagerUIAlertWithStr:@"请在系统设置中开启相册授权"WithTitle:@"相册授权未开启"WithVC:selfblock:nil];//未授权可以提示用不进入设置里面打开权限
}
}];
感谢另外一为同行的文档启发特附iOS权限获取设置