1.info配置
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
2.检测并引导
import<AVFoundation/AVCaptureDevice.h>
import <AVFoundation/AVMediaFormat.h>
import<AssetsLibrary/AssetsLibrary.h>
import<CoreLocation/CoreLocation.h>
//相机权限
AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。可能是家长控制权限
authStatus ==AVAuthorizationStatusDenied) //用户已经明确否认了这一照片数据的应用程序访问
{
// 无权限 引导去开启
NSURL *url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplicationsharedApplication]canOpenURL:url]) {
[[UIApplicationsharedApplication]openURL:url];
}
}
//相册权限
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author ==kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//无权限 引导去开启
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}