xamarin.forms - ZXING 手机重复扫描问题
问题描述
我正在使用 zing 移动扫描仪,它运行良好,但是我从不同的按钮调用相同的操作,它拒绝扫描它会打开预览窗口,但不会调用扫描。
public async void BtnScanStockTakeItem_Clicked(object sender, EventArgs e)
{
var scanPage = new ZXingScannerPage();
scanPage.ToggleTorch();
scanPage.IsScanning = true;
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
}
}
然后我从另一个按钮方法调用上面的方法让我们说保存的功能
private async void SaveFunction(object sender, EventArgs e)
{
foreach (var item in transferList)
{
int z = await restServices.PostStockTakeTransaction(item);
}
Preferences.Set("StockTakeWarehouse", pickStockTake.SelectedIndex);
WarehouseName = pickStockTake.SelectedItem.ToString();
bool x = await DisplayAlert("Test", "Item Saved", "ReScan", "Cancel");
if (x)
{
BtnScanStockTakeItem_Clicked(sender, e);
//this is where it rescans the item
}
}
字符串的事情是我没有收到任何 logcat 错误或扫描仪的视口没有显示,但由于某些原因与以前相同的条形码格式不接受扫描。
解决方案
对于其他面临类似问题的人来说,这是我的相机线程没有正确调用的事实,我必须这样做
Device.BeginInvokeOnMainThread(async () =>
{
BtnScanStockTakeItem_Clicked(sender, e);
});
按预期工作
推荐阅读
- javascript - Async api fetch with redux thunk
- html - 以 HTML 格式将文件复制到剪贴板
- linux - 用于根据文件类型将文件夹移动到相应文件夹的 Shell 脚本
- javascript - Electron - fs.readdir 回调有时不会在重新加载时执行
- android - Firestore Recycler 在一个页面(实例)中加载,但不在另一个页面中
- apache - 告诉浏览器不再指向 https,而是现在指向 http
- clickonce - 桌面应用程序用户能否从位于 LAN 服务器上的 CNG 密钥库中检索密钥
- react-native - React-native:index.js:Transformer.transform 不是函数
- typescript - Vue typescript 递归组件
- angular - 如何在飞行中取消待处理的 http api 调用?