1:导入avfoundtion框架
pch中导入头文件
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import <AssetsLibrary/AssetsLibrary.h>
2:判断的代码
if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
判断相册权限
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
无权限
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) {
照片权限被禁用" message:@"请在iPhone的'设置-隐私-照片'中允许抖抖访问你的照片" preferredStyle:UIAlertControllerStyleAlert];
确定" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
return;
}else{
照片权限被禁用" message:@"请在iPhone的'设置-隐私-照片'中允许抖抖访问你的照片" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
return;
}
}else{
//有相册权限
}
}else if (sourceType == UIImagePickerControllerSourceTypeCamera){
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
无权限
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) {
相机被禁用" message:@"请在iPhone的'设置-隐私-相机'中允许抖抖访问你的相机" preferredStyle:UIAlertControllerStyleAlert];
确定" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
return;
}else{
相机被禁用" message:@"请在iPhone的'设置-隐私-相机'中允许抖抖访问你的相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
return;
}
}else{
//有相机权限
}
}
标签:相册,nil,else,相机,message,权限,alertController
From: https://blog.51cto.com/u_16105066/6260081