美文网首页
iOS 8之后相机授权判断

iOS 8之后相机授权判断

作者: 走道牙的人 | 来源:发表于2016-08-19 14:46 被阅读9次

    参考http://blog.sina.com.cn/s/blog_b1540f630102w6zn.html

    示例代码

    // 判断相机授权
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    
    if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"没有相机权限" message:@"请去设置-隐私-相机中对52度授权" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"现在就去" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"以后再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self cancle];
        }];
        [alertController addAction:cancelAction];
        [alertController addAction:okAction];
        
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
        return;
    }
    

    相关文章

      网友评论

          本文标题:iOS 8之后相机授权判断

          本文链接:https://www.haomeiwen.com/subject/cuubsttx.html