iOS Xamarin Forms 中的 ZXing 条码扫描器无法读取条码
ZXing barcode scanner in Xamarin Forms on iOS doesn't read barcodes
我正在开发一个针对 Android 和 iOS 的 Xamarin Forms PCL 项目,它需要一些基本的条形码扫描功能。
我准备好了 运行 ZXing.Net.Mobile package following this tutorial and referencing this guide 的表单版本,它在 Android 上运行良好。然而,在 iOS 上,相机出现但 OnScanResult
事件从未触发。
我已经在几个 iOS 设备 运行 几个不同的版本(从 8.0 - 10.3 的任何地方)上测试了它,并摆弄了我能想到的一切,也参考了他们的示例项目。 ZXing.Net.Mobile
和 ZXing.Net.Mobile.Forms
nuget 包已安装在所有项目中。
这是我的扫描代码,通过在我的主页上按下按钮触发:
var scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
await Navigation.PushAsync(scanPage);
和AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
折腾了两天,感觉自己已经无计可施了。还有其他人遇到过类似的问题吗?感谢您的指导!
编辑 1
这是点击按钮触发上述代码时的设备日志输出(仅消息列)。当相机打开并指向各种条形码时,不会添加任何日志项。我在这里没有看到任何可疑的东西,但也许其他人看到了?
- 性能:分配 AVCaptureVideoPreviewLayer 花费了 14.14 毫秒。
- AppleH4CamIn::power_on_hardware
- AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - 频道:0,索引:0
- 开始扫描
- AppleH4CamIn::setPowerStateGated: 1
- ZXingScannerView.Setup() 耗时 0.167 毫秒。
- ASL 发件人统计
- AppleH4CamIn::ISP_FlushInactiveDARTMappings: 0x00000000
- AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - 频道:0,索引:0
编辑 2
我 运行 来自 github repo 的示例 Xamarin Forms PCL 并且在 iOS 上遇到了同样的问题,相机打开正常,但从未读取过条码.因此,我认为问题一定出在我的 Visual Studio and/or Xamarin 设置上。我是 运行 Visual Studio 稳定版 Xamarin 频道的 2015 社区。
add this on ios
protected override void OnAppearing()
{
base.OnAppearing();
qrcode.IsScanning = true;
}`enter code here`
protected override void OnDisappearing()
{
qrcode.IsScanning = false;
base.OnDisappearing();
}
我终于开始使用 this project 作为起点。这只是一个使用 ZXing 的基本条码扫描实现,但无论出于何种原因,我终于可以在 iOS.
上读取条码
可能是版本问题,但我无法缩小范围。
编辑
我在 Xamarin 论坛上发布了同样的问题:https://forums.xamarin.com/discussion/comment/272209#Comment_272209
看来答案是降级到ZXing 2.1.47版本。我已经几个月没有使用该库进行任何工作,所以我没有测试新版本。
试试这个:
scanPage.IsAnalyzing = true;
IsAnalyzing
不同于 IsScanning
。
我遇到了和你一样的问题。但是用了之后IsAnalyzing = true;
就固定了
我正在开发一个针对 Android 和 iOS 的 Xamarin Forms PCL 项目,它需要一些基本的条形码扫描功能。
我准备好了 运行 ZXing.Net.Mobile package following this tutorial and referencing this guide 的表单版本,它在 Android 上运行良好。然而,在 iOS 上,相机出现但 OnScanResult
事件从未触发。
我已经在几个 iOS 设备 运行 几个不同的版本(从 8.0 - 10.3 的任何地方)上测试了它,并摆弄了我能想到的一切,也参考了他们的示例项目。 ZXing.Net.Mobile
和 ZXing.Net.Mobile.Forms
nuget 包已安装在所有项目中。
这是我的扫描代码,通过在我的主页上按下按钮触发:
var scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
await Navigation.PushAsync(scanPage);
和AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
折腾了两天,感觉自己已经无计可施了。还有其他人遇到过类似的问题吗?感谢您的指导!
编辑 1
这是点击按钮触发上述代码时的设备日志输出(仅消息列)。当相机打开并指向各种条形码时,不会添加任何日志项。我在这里没有看到任何可疑的东西,但也许其他人看到了?
- 性能:分配 AVCaptureVideoPreviewLayer 花费了 14.14 毫秒。
- AppleH4CamIn::power_on_hardware
- AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - 频道:0,索引:0
- 开始扫描
- AppleH4CamIn::setPowerStateGated: 1
- ZXingScannerView.Setup() 耗时 0.167 毫秒。
- ASL 发件人统计
- AppleH4CamIn::ISP_FlushInactiveDARTMappings: 0x00000000
- AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - 频道:0,索引:0
编辑 2
我 运行 来自 github repo 的示例 Xamarin Forms PCL 并且在 iOS 上遇到了同样的问题,相机打开正常,但从未读取过条码.因此,我认为问题一定出在我的 Visual Studio and/or Xamarin 设置上。我是 运行 Visual Studio 稳定版 Xamarin 频道的 2015 社区。
add this on ios
protected override void OnAppearing()
{
base.OnAppearing();
qrcode.IsScanning = true;
}`enter code here`
protected override void OnDisappearing()
{
qrcode.IsScanning = false;
base.OnDisappearing();
}
我终于开始使用 this project 作为起点。这只是一个使用 ZXing 的基本条码扫描实现,但无论出于何种原因,我终于可以在 iOS.
上读取条码可能是版本问题,但我无法缩小范围。
编辑
我在 Xamarin 论坛上发布了同样的问题:https://forums.xamarin.com/discussion/comment/272209#Comment_272209
看来答案是降级到ZXing 2.1.47版本。我已经几个月没有使用该库进行任何工作,所以我没有测试新版本。
试试这个:
scanPage.IsAnalyzing = true;
IsAnalyzing
不同于 IsScanning
。
我遇到了和你一样的问题。但是用了之后IsAnalyzing = true;
就固定了