Xamarin表单不调试和ZXing冻结所有应用程序

问题描述 投票:0回答:1

我申请在Xamarin上使用Zxing阅读一些QR码。前天,它运作良好,但从昨天起我就遇到了这个问题:

我在OnAppearing()方法中放了一个断点,但它被忽略了,好吧......当我点击Zxing按钮,打开扫描仪时,应用程序停止,但不显示任何内容,只有冻结,没有错误,没有消息,没有调试,没有。我的代码与它工作时的代码相同,没有任何改变。如果有人能帮助我,我将不胜感激。

    public MainPage()
    {
        InitializeComponent();
        this.InitializeComponent();

        this.BindingContext = this;

        this.IsBusy = false;
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        var dados = new AcessoDB();

        if (dados.GetAlunos().Count() > 0)
        {
            var infopage = new Wallet();
            Navigation.InsertPageBefore(infopage, Navigation.NavigationStack[0]);
            await Navigation.PopToRootAsync();
            codeqr.IsEnabled = false;
        }
    }

    private async void Scan_Clicked(object sender, EventArgs e)
    {
        semaphoreSlim.Release();
        string img;
        this.IsBusy = true;


        if (CrossConnectivity.Current.IsConnected)
        {
            var scan = new ZXingScannerPage();
            await Navigation.PushAsync(scan);
            scan.OnScanResult += async (result) =>
            {
                bool liberado = await semaphoreSlim.WaitAsync(-1);
                if (!liberado)
                {
                    return;
                }
                scan.IsScanning = false;
                Device.BeginInvokeOnMainThread(async () =>
                {
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        var parseResult = ResultParser.parseResult(result);

                        if (parseResult != null)
                        {
                            var hash = sha256_hash(result.ToString());
                            Aluno items = new Aluno();
                            try
                            {
                                scan.IsAnalyzing = false;
                                scan.IsScanning = false;
                                items = JsonConvert.DeserializeObject<Aluno>(result.ToString());
                                img = GetImage(items.Foto);
                            }
                            catch (Exception)
                            {
                                scan.IsScanning = false;
                                scan.IsAnalyzing = false;
                                await Navigation.PopAsync();
                                await DisplayAlert("Ops...", "Ocorreu algum erro com a leitura do seu código, tente de novo.", "Ok!");
                                return;
                            }
                            var info = new Aluno
                            {
                                Matricula = items.Matricula,
                                Nome = items.Nome,
                                RG = items.RG,
                                Nascimento = items.Nascimento,
                                Curso = items.Curso,
                                Campus = items.Campus,
                                Periodos = items.Periodos,
                                Modalidade = items.Modalidade,
                                Validade = items.Validade,
                                Hash = hash,
                                Foto = img
                            };

                            var infopage = new Wallet();
                            var dados = new AcessoDB();

                            if (!await dados.InserirAlunoAsync(info))
                            {
                                scan.IsAnalyzing = false;
                                scan.IsScanning = false;
                                await Navigation.PopAsync();
                                await DisplayAlert("Ops...", "Esse código não consta no nosso banco de dados, tem certeza que estuda no UGB?", "Repetir");
                                return;
                            }

                            try
                            {
                                scan.IsScanning = false;
                                scan.IsAnalyzing = false;
                                infopage.BindingContext = info;
                                Navigation.InsertPageBefore(infopage, Navigation.NavigationStack[0]);
                                await Navigation.PopToRootAsync();
                            }
                            catch (Exception)
                            {
                                scan.IsScanning = false;
                                scan.IsAnalyzing = false;
                                await DisplayAlert("Erro", "Não foi possível carregar a sua carteirinha.", "Ok...");
                            }
                        }
                    }
                });
            };
        }
        else
        {
            await DisplayAlert("Ops...", "Você não está conectado à internet.", "Ok!");
        }
        this.IsBusy = false;
    }

    public string GetImage(string foto)
    {
        if (String.IsNullOrEmpty(foto))
        {
            return "";
        }

        using (var WebClient = new WebClient())
        {
            var imageBytes = WebClient.DownloadData("http://portal.ugb.edu.br/upload/ImagemAluno/" + foto);
            var sxtyfr = Convert.ToBase64String(imageBytes);
            //var img = "data:image/jpg;base64," + sxtyfr;
            return sxtyfr;
        }
    }

    public static string sha256_hash(string value)
    {

        StringBuilder Sb = new StringBuilder(); using (SHA256 hash = SHA256Managed.Create())
        {

            Encoding enc = Encoding.UTF8;

            Byte[] result = hash.ComputeHash(enc.GetBytes(value)); foreach (Byte b in result)

                Sb.Append(b.ToString("x2"));

        }
        return Sb.ToString();

    }
}

}

debugging xamarin xamarin.forms xamarin.android zxing
1个回答
0
投票

我解决了我的问题...我只是清理,构建并重建解决方案,然后发生魔术。谢谢大家帮帮我。

© www.soinside.com 2019 - 2024. All rights reserved.