我正在尝试向我的Xamarin.iOS应用程序添加条形码扫描功能。我是从Visual Studio开发的,并从Xamarin组件商店中添加了Zxing.Net.Mobile组件。
我已按示例实现它:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
问题在于当我点击扫描按钮时,捕获视图会正确显示,但如果我尝试捕获条形码,则没有任何反应,似乎扫描仪无法识别任何条形码。
有人遇到过这个问题吗?我该如何解决?
提前感谢您的帮助!