iOS获取相机、麦克风权限

判断相机权限

+ (BOOL)isCameraAuthorization {
    NSString *mediaType = AVMediaTypeVideo;//读取媒体类型
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];//读取设备授权状态
    if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusNotDetermined) {
        return NO;
    }
    return YES;
}

请求授权

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        if (granted) {
            // 允许
        } else {
            // 拒绝
        }
    }];

 

麦克风同相机,修改传入枚举类型

你可能感兴趣的:(iOS开发)