Xamarin iOS Zxing与ZXingScannerView

时间:2017-10-28 14:00:05

标签: xamarin.ios navigation zxing

扫描完成后需要立即导航到其他视图 将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方法。

1 个答案:

答案 0 :(得分:1)

您遇到的问题是,您尝试在异步任务中运行与UI相关的代码。在主线程内进行导航

            BeginInvokeOnMainThread(
                () =>
                {
                    scannerView.StopScanning();
                    // Navigate code goes here
                });