关闭

判断是否允许使用相机

8845人阅读 评论(0) 收藏 举报

注意:此方法只对ios7以上的系统有用,刚才用“我查查”试了下,如果是在ios6的系统的话就直接崩溃了,况且ios6上也没有“设置--隐私--相机” 那一项

NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio

    

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

    

    // This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.

    if(authStatus ==AVAuthorizationStatusRestricted){

        NSLog(@"Restricted");

    }

    

    // The user has explicitly denied permission for media capture.

    elseif(authStatus == AVAuthorizationStatusDenied){

        NSLog(@"Denied");     //应该是这个,如果不允许的话

    }

    

    // The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.

    elseif(authStatus == AVAuthorizationStatusAuthorized){

        NSLog(@"Authorized");

    }

    

    // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.

    elseif(authStatus == AVAuthorizationStatusNotDetermined){

        

        [AVCaptureDevicerequestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {

            if(granted){

                NSLog(@"Granted access to %@", mediaType);

            }

            else {

                NSLog(@"Not granted access to %@", mediaType);

            }

        }];

        

    }

    

    else {

        NSLog(@"Unknown authorization status");

    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2304802次
    • 积分:23824
    • 等级:
    • 排名:第293名
    • 原创:413篇
    • 转载:638篇
    • 译文:0篇
    • 评论:103条
    最新评论