iOS二维码扫描//设置条码类型 ****.metadataObjectTypes =@[AVMetadataObjectTypeQRCode];崩溃问题

二维码扫描在设置条码类型时出现崩溃

崩溃位置如下图所示:

崩溃位置.png

提示错误如下:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMetadataOutput setMetadataObjectTypes:] Unsupported type found - use -availableMetadataObjectTypes'
*** First throw call stack:
(0x1826241c0 0x18105c55c 0x189db1898 0x10014e298 0x1884663dc 0x188465fa4 0x188e29d34 0x1887b0d28 0x1887d2194 0x1887d5060 0x188558e80 0x1003a4c34 0x18849b7b0 0x18849b730 0x188485be4 0x18849b01c 0x188a2bf30 0x188a27fc8 0x188a27ae8 0x188a26da4 0x188495d70 0x188466858 0x188c53cb8 0x188c4d720 0x1825d2278 0x1825d1bc0 0x1825cf7c0 0x1824fe048 0x183f81198 0x1884d1628 0x1884cc360 0x1003d0474 0x1814e05b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

崩溃原因:

由于关于项目的中的相机授权在设备系统中没有打开,并且项目中没有对相机授权开启作出判断导致的崩溃。

解决办法:

在代码中设置条码类型以前进行系统相机授权判断即可

    NSString *mediaType = AVMediaTypeVideo;
    
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
    
    if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
        
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"请在iPhone的“设置”-“隐私”-“相机”功能中,找到“(自己项目名称)”打开相机访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        alert.delegate = self;
        [alert show];
        
        return;
        
    }

你可能感兴趣的:(iOS二维码扫描//设置条码类型 ****.metadataObjectTypes =@[AVMetadataObjectTypeQRCode];崩溃问题)