IOS-系统提示框

没有授权之前是不能进行操作摄像头的,使用之前先弹出系统的

        AVCaptureDevice *captureDevice=[self getCameraDeviceWithPosition:AVCaptureDevicePositionBack];//取得后置摄像头
        if (!captureDevice) {
//            NSLog(@"取得后置摄像头时出现问题.");
        }

        NSError *error=nil;
        //根据输入设备初始化设备输入对象,用于获得输入数据
        AVCaptureDeviceInput  *captureDeviceInput=[[AVCaptureDeviceInput alloc]initWithDevice:captureDevice error:&error];
        if (error) {

        }
    然后实际上在弹出自己的

        //            检测麦克风功能是否打开
        [[AVAudioSession sharedInstance]requestRecordPermission:^(BOOL granted) {
            if (!granted)
            {

                [self showAlertView:@"热波间需要访问你的麦克风" message:@"使用手机直播,热波间需要访问你的麦克风权限。点击“设置”前往系统设置允许热波间访问你的麦克风" confirm:^(id sender) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                    [self stopPlayingautoExitRoom];
                } cancel:^(id sender) {
                    [self stopPlayingautoExitRoom];
                }];
                return ;
            }else{



            }


        }];

        //检测摄像头功能是否打开
        NSString *mediaType1 = AVMediaTypeVideo;
        AVAuthorizationStatus authStatus1 = [AVCaptureDevice authorizationStatusForMediaType:mediaType1];

        if (authStatus1 == 0) {
            return;
        }
        if(authStatus1 == AVAuthorizationStatusRestricted || authStatus1 == AVAuthorizationStatusDenied ){

            [self showAlertView:@"热波间需要访问你的相机" message:@"使用手机直播,热波间需要访问你的相机权限。点击“设置”前往系统设置允许热波间访问你的相机" confirm:^(id sender) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                [self stopPlayingautoExitRoom];
            } cancel:^(id sender) {
                [self stopPlayingautoExitRoom];
            }];


            return;
        }

对以上做了修改

  NSString *mediaType = AVMediaTypeVideo;
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

        if(authStatus ==AVAuthorizationStatusRestricted){//此应用程序没有被授权访问的照片数据。可能是家长控制权限。

        }else if(authStatus == AVAuthorizationStatusDenied){// 用户已经明确否认了这一照片数据的应用程序访问
            [self showAlertView:@"热波间需要访问你的相机" message:@"使用手机直播,热波间需要访问你的相机权限。点击“设置”前往系统设置允许热波间访问你的相机" confirm:^(id sender) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

            } cancel:^(id sender) {

            }];
            return;
        }
        else if(authStatus == AVAuthorizationStatusAuthorized){//用户已授权应用访问照片数据.

            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            picker.allowsEditing = YES;
            picker.sourceType = sourceType;
            picker.mediaTypes = @[(NSString *) kUTTypeImage];
            [self presentViewController:picker animated:YES completion:nil];

        }else if(authStatus == AVAuthorizationStatusNotDetermined){// 用户尚未做出了选择这个应用程序的问候.一次一出现

            [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {//弹出授权弹框
                if(granted){//点击允许访问时调用
                            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                            picker.delegate = self;
                            picker.allowsEditing = YES;
                            picker.sourceType = sourceType;
                            picker.mediaTypes = @[(NSString *) kUTTypeImage];
                            [self presentViewController:picker animated:YES completion:nil];
                }
                else {
                    return ;
                }

            }];
        }else {
            NSLog(@"Unknown authorization status");
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值