美文网首页
iOS 获取系统相机权限弹窗点击事件

iOS 获取系统相机权限弹窗点击事件

作者: 烟雨痕 | 来源:发表于2018-08-07 10:23 被阅读373次

    参考:https://blog.csdn.net/zhao15127334470/article/details/81216876

    拍照
        UIAlertAction * takePhoto = [UIAlertAction actionWithTitle:DKLang(@"拍照", @"拍照") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
            
            AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            
            if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
                NSString *aleartMsg = @"";
                aleartMsg = @"请在\"设置 - 隐私 - 相机\"选项中,允许多客访问您的相机";
                
                UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:aleartMsg delegate:nil cancelButtonTitle:DKLang(@"OK", @"确定") otherButtonTitles:nil];
                [alert show];
                return;
            }
            //获取访问相机权限时,弹窗的点击事件获取
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (granted) {
                    debugLog(@"允许了");
                    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
                    //判断是否有摄像头
                    if([UIImagePickerController isSourceTypeAvailable:sourceType])
                    {
                        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
                        imagePickerController.delegate = self;   // 设置委托
                        imagePickerController.sourceType = sourceType;
                        imagePickerController.allowsEditing = NO;
                        //需要以模态的形式展示
                        [self presentViewController:imagePickerController animated:YES completion:^{
                            
                        }];  
                    } 
                } else {
                        debugLog(@"被拒绝了");
                }
            }];
            
        }];
    

    相关文章

      网友评论

          本文标题:iOS 获取系统相机权限弹窗点击事件

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