• 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();


  • 相关阅读:
    摩尔定律 四
    为什么要重载new? 四
    JS 完美识别IE FIREFOX CHROME safari
    Chrome的JS调试工具
    JetBrains WebStorm 6注册码(其实版本v4, v5, v6都通用)
    require.js 入门学习
    str_replace、preg_replace、strtr比较
    获取当前IP地址,跳转到对应城市网站。
    mysql大数据高并发处理(转)
    SESSION的安全性(转)
  • 原文地址:https://www.cnblogs.com/AlvinCrash/p/5379440.html
Copyright © 2020-2023  润新知