Xamarin iOS Zxing 与 ZXingScannerView
Xamarin iOS Zxing with ZXingScannerView
需要在扫描完成后立即导航到其他视图
将 Zxing 与 ZXingScannerView 结合使用
使用此代码
scannerView.StartScanning(async (result) =>
{
if (!ContinuousScanning)
{
Console.WriteLine("Stopping scan...");
Console.WriteLine("Result: " + result.Text);
scannerView.StopScanning();
if (result != null)
{
await GetScannedDetails(result.Text);
// here i need to navigate to other screen
}
}
var evt = this.OnScannedResult;
if (evt != null) evt(result);
}, this.ScanningOptions);
当我尝试导航时出现此错误
一致性错误:您正在调用只能从 UI 线程调用的 UIKit 方法。
您遇到的问题是,您尝试在异步任务中 运行 UI 相关代码。在主线程中进行导航
BeginInvokeOnMainThread(
() =>
{
scannerView.StopScanning();
// Navigate code goes here
});
需要在扫描完成后立即导航到其他视图
将 Zxing 与 ZXingScannerView 结合使用
使用此代码
scannerView.StartScanning(async (result) =>
{
if (!ContinuousScanning)
{
Console.WriteLine("Stopping scan...");
Console.WriteLine("Result: " + result.Text);
scannerView.StopScanning();
if (result != null)
{
await GetScannedDetails(result.Text);
// here i need to navigate to other screen
}
}
var evt = this.OnScannedResult;
if (evt != null) evt(result);
}, this.ScanningOptions);
当我尝试导航时出现此错误
一致性错误:您正在调用只能从 UI 线程调用的 UIKit 方法。
您遇到的问题是,您尝试在异步任务中 运行 UI 相关代码。在主线程中进行导航
BeginInvokeOnMainThread(
() =>
{
scannerView.StopScanning();
// Navigate code goes here
});