• iOS开发调用相机时出现黑屏的解决办法(原因:没有获取到相机权限)


    iOS开发调用相机时出现黑屏的解决办法(原因:没有获取到相机权限)

    在开发过程中调用系统相机,但是页面出现黑屏,原因是自己只进行了部分的相机权限的判断没有根据系统的版本判断,

     

     

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
            
            AVAuthorizationStatus authStatus =  [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
            
            if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted)
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"打开相机权限" message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                    if([[UIApplication sharedApplication] canOpenURL:url]) {
                        [[UIApplication sharedApplication] openURL:url];
                    }
                }];
                UIAlertAction *canleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
                [alert addAction:okAction];
                [alert addAction:canleAction];
                [self presentViewController:alert animated:YES completion:nil];
                return;
               
            }
        }else{
            ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
            if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied)
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"打开相机权限" message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                    if([[UIApplication sharedApplication] canOpenURL:url]) {
                        [[UIApplication sharedApplication] openURL:url];
                    }
                }];
                UIAlertAction *canleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
                [alert addAction:okAction];
                [alert addAction:canleAction];
                [self presentViewController:alert animated:YES completion:nil];
                return;
            }
        }
    

     

     

  • 相关阅读:
    [置顶] 基于平板电脑的面访调查
    spring技术翻译开始
    (3)选择元素——(9)为交替的列加样式(Styling alternate rows)
    网页换肤
    djano-cms学习笔计(一)
    【Android】Activity的菜单机制和方法解析
    canvas
    Flexbox-CSS3弹性盒模型flexbox完整版教程
    原生js获取鼠标坐标方法全面讲解:clientX/Y,pageX/Y,offsetX/Y,layerX/Y,screenX/Y
    怎么使用jquery判断一个元素是否含有一个指定的类(class)
  • 原文地址:https://www.cnblogs.com/Rong-Shengcom/p/9189940.html
Copyright © 2020-2023  润新知