代码如下:
// 相册权限
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {
NSLog(@"请在手机的设置-隐私-照片中,允许xxx访问");
return;
}
// 相机权限
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
NSLog(@"请在手机的设置-隐私-相机中,允许xxx访问");
return;
}
// 直接跳转app对应的设置中
NSURL*url=[NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
//保存本地相册
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:image.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
if (!error) {
}
}];
对应的枚举列表:
typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
ALAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
ALAuthorizationStatusRestricted , // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
ALAuthorizationStatusDenied , // 用户已经明确否认了这一照片数据的应用程序访问
ALAuthorizationStatusAuthorized // 用户已经授权应用访问照片数据
}
网友评论