判断是否允许使用相机

注意:此方法只对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");

    }

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenyong05314/article/details/17094781
上一篇保存图片到相册 iphone UIImageWriteToSavedPhotosAlbum 保存图片
下一篇UITextView 实现placeholder的方法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭