1

我将这个库用于我的 Xamarin.Forms 应用程序:https ://github.com/Redth/ZXing.Net.Mobile

刚开始,它可以在 Android 上完美运行。iOS 显示相机取景器,但它无法识别任何条形码。

我根据需要在我的 AppDelegate 中初始化它:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();

    ZXing.Net.Mobile.Forms.iOS.Platform.Init();
    LoadApplication(new App(new iOSInitializer()));

    return base.FinishedLaunching(app, options);
}

我还在 Info.plist 中设置了权限描述:

<key>NSCameraUsageDescription</key>
<string>Please allow access to the camera to scan barcodes</string>

但我想这很明显,否则相机取景器也不起作用。

4

1 回答 1

0

我在我的应用程序中也遇到了 Zxing 的一些问题,但我注意到在 Android 和 IOS 中使用正确的版本解决了一些问题,我目前使用的是 2.3.1 版本(不是 2.4.1)并且工作完美,此外,我意识到你不应该首先在堆栈中使用你的 ZxingPage ,这就是为什么我总是在之前放置一个页面以避免任何崩溃:

 var root = Application.Current.MainPage.Navigation.NavigationStack[0];
            Application.Current.MainPage.Navigation.InsertPageBefore(new View(), root);

然后我调用 ZxingPage。希望能帮助到你 :)

于 2020-05-17T17:15:59.407 回答