ZXing.NET 命名空间在 .NET IOS 项目上不可用

问题描述 投票:0回答:1

我们正在将 Xamarin.iOS 应用程序升级到 .NET7。我们需要使用相机读取条形码,我们在 .NET 7 IOS 应用程序上使用 ZXing.Mobile nuget。

我需要添加以下行来初始化环境 ZXing.Net.Mobile.Forms.iOS.Platform.Init();

但是,ZXing.Net命名空间并没有出现。在调用 Scanner.Scan() 方法时,出现错误 System.NotSupportedException:此平台不支持 MobileBarcodeScanner。

不知道我在这里错过了什么。这个 nuget 与 net8-ios 兼容吗?

在调用 Scanner.Scan() 方法时,我期待相机出现,但它没有出现。

.net xamarin.ios zxing.net.mobile
1个回答
0
投票

在毛伊岛,您应该安装ZXing.Net.Maui.Controls,它支持

.NET 8

要初始化插件,只需在

.UseBarcodeReader()
中添加
MauiProgram.cs
,如下所示:

// Add the using to the top
using ZXing.Net.Maui;
using ZXing.Net.Maui.Controls;


public static MauiApp Create()
{
    var builder = MauiApp.CreateBuilder();

    builder
        .UseMauiApp<App>()
        .UseBarcodeReader(); // Make sure to add this line

    ...
}

对于 iOS,请转到您的

info.plist
文件(在 Platforms\iOS 文件夹下)并在 dict 节点内添加以下权限:

<key>NSCameraUsageDescription</key>
<string>This app uses barcode scanning to...</string>

确保您为应用程序访问摄像头输入明确且有效的原因。此描述将显示给用户。

您可以参考github repo了解更多详情。

© www.soinside.com 2019 - 2024. All rights reserved.