Search code examples
xamarinxamarin.formsvisual-studio-2015xamarin-studio

Using ZXingScannerPage with XF, my content page has weird behavior


I am making an app in xamarin forms of which I will have a login similar to that of whatapp web, an on-screen qr that will be scanned by the phone, in the emulator with visual studio 2017 I have no problems, but when I export the app to an apk and the I install on a mobile device, the app reads the qr and returns to the previous login screen, not showing any reaction, which should be to go to the next screen where I have a dashboard.

What can be? I enclose my code used.

 btnScanQRCode.IsEnabled = false;
        var scan = new ZXingScannerPage();

        scan.OnScanResult += (result) =>
        {
            scan.IsScanning = false;
            Device.BeginInvokeOnMainThread(async () =>
            {
                await Application.Current.MainPage.Navigation.PopAsync();
                var resultado = JsonConvert.DeserializeObject<QrCode>(result.Text);

                JObject qrObject = JObject.Parse(JsonConvert.SerializeObject(resultado));
                JsonSchema schema = JsonSchema.Parse(SettingHelper.SchemaJson);

                bool valid = qrObject.IsValid(schema);

                if (valid == true)
                {
                    App.Database.InsertQrCode(resultado);
                    QrCode qr = App.Database.GetQrCode();
                    await _viewModel.Login();                
                    await Navigation.PushAsync(new Organization());
                }
                else
                {
                    await DisplayAlert("False", JsonConvert.SerializeObject(resultado), "ok");
                }
            });
        };
        await Application.Current.MainPage.Navigation.PushAsync(scan);
        btnScanQRCode.IsEnabled = true;

Solution

  • This was originally a comment, but through the writing i realized this is the answer.

    You need to debug your code. Attach a device and deploy the app in Debug config. Step through your code and see where it fails.

    It sounds like it's crashing silently and probably on the line where you Deserialize result.Text in a QrCode. result.Text is just a string and will never deserialize into an object. You probably need a constructor that takes a string like QrCode(result.Text).