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

参考: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(@"被拒绝了");
            }
        }];
        
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,179评论 25 708
  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,213评论 12 197
  • 本系列出于AWeiLoveAndroid的分享,在此感谢,再结合自身经验查漏补缺,完善答案。以成系统。 Andro...
    济公大将阅读 1,844评论 2 10
  • 你说你喜欢雨,但是下雨的时候你却撑开了伞; 你说你喜欢阳光,但当阳光播撒的时候,你却躲在阴凉之地; 你说你喜欢风,...
    书中屋_阅读 75评论 0 0
  • 感恩: 1.妈妈为我准备饮食、清理房间地面 2. 3. 4. 5. 善...
    lucky思齐阅读 139评论 0 0