检查获取授权状态
+ (AVAuthorizationStatus)authorizationStatusForMediaType:(AVMediaType)mediaType NS_AVAILABLE_IOS(7_0);
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
AVAuthorizationStatusNotDetermined = 0,
AVAuthorizationStatusRestricted = 1,
AVAuthorizationStatusDenied = 2,
AVAuthorizationStatusAuthorized = 3,
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
请求授权
+ (void)requestAccessForMediaType:(AVMediaType)mediaType completionHandler:(void (^)(BOOL granted))handler NS_AVAILABLE_IOS(7_0);
使用实例
//相机授权
- (void)accessPhotoRights{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
//相机权限受限
}else if (authStatus ==AVAuthorizationStatusNotDetermined){
//等待授权
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted){
//同意授权
if ([NSThread isMainThread]) {
}else{
dispatch_async(dispatch_get_main_queue(), ^{
});
}
}else {
//拒绝授权
}
}];
}else if (authStatus == AVAuthorizationStatusAuthorized){
//已经授权
}
}