美文网首页
iOS 12 下调用相机闪退,

iOS 12 下调用相机闪退,

作者: 陌上北辰 | 来源:发表于2018-06-09 22:12 被阅读314次

    plist文件中权限已配置,Privacy - Camera Usage Description,iOS 12以下没问题,但是在iOS 12 beta 的时候就闪退

    //判断是否已授权
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusDenied||authStatus == AVAuthorizationStatusRestricted) {
            [FNSystemSet gotoSetCamera:self];
            return ;
        }
    }
    
    //获取相机权限
    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        NSLog(@"%@",granted ? @"相机准许":@"相机不准许");
    }];
    
    // 判断是否可以打开相机
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
        [self presentViewController: [self selectPicture:UIImagePickerControllerSourceTypeCamera]
                           animated:YES
                         completion:^{
                         }];
    } else {
        FNLog(@"没有相机");
    }
    

    最终解决:是在plist文件中加入麦克风权限就OK了

    相关文章

      网友评论

          本文标题:iOS 12 下调用相机闪退,

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