You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iPhone15(iOS17.3.1)使用ZXing扫码报NotSupportedException问题求助

解决Xamarin.iOS中ZXing在iPhone15真机扫码报错的问题

问题重现

使用ZXing.Mobile扫码代码:

ZXing.Result result = await scanner.Scan(new ZXing.Mobile.MobileBarcodeScanningOptions()
{
    AutoRotate = true,
}, true);

在iPhone15(iOS17.3.1)真机调试时抛出错误:
System.NotSupportedException: "humanFullBody" has no associated enum value on this platform.'
但相同iOS版本的iPhone12真机及iPhone15模拟器运行正常。

解决方案

1. 显式指定扫码格式,规避默认不支持类型

问题根源是ZXing.Mobile在新机型上默认尝试识别的格式包含了当前平台不支持的humanFullBody类型,显式指定仅需要的二维码格式即可解决:

var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
{
    AutoRotate = true,
    // 只启用QR Code格式,可根据需求添加其他需要的条码格式
    PossibleFormats = new List<ZXing.BarcodeFormat> { ZXing.BarcodeFormat.QR_CODE }
};
ZXing.Result result = await scanner.Scan(options, true);

2. 更新ZXing.Mobile NuGet包到最新兼容版本

旧版本的ZXing.Mobile可能未适配iOS17.3.1及iPhone15的新API,尝试更新ZXing.Mobile包到最新稳定版,确保包内的平台枚举映射已适配新机型。

3. 手动过滤不支持格式(临时方案)

如果更新包后仍无法解决,可手动过滤掉包含humanFullBody的相关设置:

// 初始化扫码器前清除不支持的格式
ZXing.Mobile.MobileBarcodeScanner.DefaultOptions.PossibleFormats = 
    ZXing.Mobile.MobileBarcodeScanner.DefaultOptions.PossibleFormats
    .Where(f => 
    {
        try
        {
            // 尝试解析枚举值,跳过无法识别的项
            Enum.Parse(typeof(ZXing.BarcodeFormat), f.ToString());
            return true;
        }
        catch
        {
            return false;
        }
    })
    .ToList();

内容的提问来源于stack exchange,提问作者Gith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:52:04