IOS7权限检测

ios7开始,用户可以在设置->隐私->中开启或关闭某些系统权限,比如访问相册,相机 ,通讯录,地图,麦克风等。

因此,在我们的程序中,如果要访问系统的某些功能,则最好判断一下权限是否开启。否则用户不能正常使用,也一头雾水,还以为程序出错了。

下面总结一下:相册与麦克风的权限判断(目前只用到了这两个……^_^)


相机:

 AVAuthorizationStatus authstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

    if (authstatus == AVAuthorizationStatusRestricted || authstatus == AVAuthorizationStatusDenied) //用户关闭了权限

    {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"相机权限未开启") delegate:self cancelButtonTitle:NSLocalizedString(@"OK",@"确定") otherButtonTitles:nil, nil];

        alertView.delegate = self;

        [alertView show];

    }

    else if (authstatus == AVAuthorizationStatusNotDetermined) //第一次使用,则会弹出是否打开权限

    {

        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {

            if (granted)

            {

                 _output.metadataObjectTypes =@[AVMetadataObjectTypeQRCode];

            }

        }];

    }

    else if (authstatus == AVAuthorizationStatusAuthorized)

    {

         _output.metadataObjectTypes =@[AVMetadataObjectTypeQRCode];


    }



麦克风:

      //检测麦克风功能是否打开

        [[AVAudioSession sharedInstance]requestRecordPermission:^(BOOL granted) {

            if (!granted)

            {

                [ViewUtil alertViewWithString:NSLocalizedString(@"麦克风功能未开启", nil)];

            }

            else

            {

                

                [self record:sender];

            }

        }];



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值