1.info配置
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能訪問相冊</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能訪問相機</string>
2.檢測并引導(dǎo)
import<AVFoundation/AVCaptureDevice.h>
import <AVFoundation/AVMediaFormat.h>
import<AssetsLibrary/AssetsLibrary.h>
import<CoreLocation/CoreLocation.h>
//相機權(quán)限
AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus ==AVAuthorizationStatusRestricted ||//此應(yīng)用程序沒有被授權(quán)訪問的照片數(shù)據(jù)既绩。可能是家長控制權(quán)限
authStatus ==AVAuthorizationStatusDenied) //用戶已經(jīng)明確否認了這一照片數(shù)據(jù)的應(yīng)用程序訪問
{
// 無權(quán)限 引導(dǎo)去開啟
NSURL *url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplicationsharedApplication]canOpenURL:url]) {
[[UIApplicationsharedApplication]openURL:url];
}
}
//相冊權(quán)限
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author ==kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//無權(quán)限 引導(dǎo)去開啟
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}