zoukankan      html  css  js  c++  java
  • iOS 第一次安装应用,拒绝相机调用,页面卡死的解决方案

    void (^allowBlock)() = ^{

            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

            imagePicker.delegate = self;

            imagePicker.allowsEditing = YES;

            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

            if (iOS8) {

                imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;

            }

            UIViewController *ctl = [[[UIApplication sharedApplication] windows]lastObject].rootViewController;

            [ctl presentViewController:imagePicker animated:YES completion:nil];

        };

        NSString *mediaType = AVMediaTypeVideo;//读取媒体类型

        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];//读取设备授权状态

        if (authStatus == AVAuthorizationStatusNotDetermined) {

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

                dispatch_async(dispatch_get_main_queue(), ^{

                    if (granted) {

                        //第一次用户接受

                        allowBlock();

                    }else{

                        //用户拒绝

                        showAlert(@"已拒绝授权,打开相机失败");

                    }

                });

            }];

            return;

        }

        if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){

            showAlert(@"相机权限受限,请在设置中启用");

            return;

        }

        allowBlock();


  • 相关阅读:
    【linux 高级网络应用】1,2-企业IP规划部署实战,ip地址和子网划分
    【linux CCNP】4,5-linux网络及OIS-TCP/IP
    【linux CCNP】3-linux网络抓包和TCP三次握手
    【linux CCNA】1和2-linux网络基础知识入门 与 tcp协议
    CephFS文件储存
    OSD纵向扩容
    CEPH之对象存储
    CEPH之块存储
    ceph_dashboard
    ceph 创建和删除osd
  • 原文地址:https://www.cnblogs.com/AlvinCrash/p/5379440.html
Copyright © 2011-2022 走看看