判断是否允许使用相机

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


if(IOS7)
    {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusNotDetermined)
        {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if(granted){
                    UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
                    pickerController.delegate = self;
                    pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
                    pickerController.allowsEditing = NO;
                    [self presentViewController:pickerController animated:YES completion:^{
                    }];
                }
                else
                {
                    return;
                }
            }];
        }
        else if (authStatus == AVAuthorizationStatusDenied)
        {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle: nil
                                                            message:@"请在iPhone的\"设置-隐私-相机\"选项中,允许xx访问你的相机。"
                                                           delegate:nil
                                                  cancelButtonTitle: @"确定"
                                                  otherButtonTitles:nil, nil];
            [alert show];
        }
        else if (authStatus == AVAuthorizationStatusAuthorized)
        {
            UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
            pickerController.delegate = self;
            pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            pickerController.allowsEditing = NO;
            [self presentViewController:pickerController animated:YES completion:^{
            }];
        }
        else if (authStatus == AVAuthorizationStatusRestricted)
        {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle: nil
                                                            message:@"请在iPhone的\"设置-隐私-相机\"选项中,允许xx访问你的相机。"
                                                           delegate:nil
                                                  cancelButtonTitle: @"确定"
                                                  otherButtonTitles:nil, nil];
            [alert show];
        }
        
    }
    else
    {
        UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
        pickerController.delegate = self;
        pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        pickerController.allowsEditing = NO;
        [self presentViewController:pickerController animated:YES completion:^{
        }];
    }


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值