ZxingScannerPage issue in Xamarin IOS

67 views
Skip to first unread message

Chris Henderson

unread,
Jul 9, 2016, 7:50:19 PM7/9/16
to zxing
I am using the following code which works great, the first time it's called. Any subsequent calls don't actually show the scanner page at all.
buttonScanDefaultOverlay = new Button {
Text = "Scan with Default Overlay",
};
buttonScanDefaultOverlay.Clicked += async delegate {

await DisplayAlert("xxx.com", "button press", "OK");

try
{
ZXing.Mobile.MobileBarcodeScanningOptions opt = new ZXing.Mobile.MobileBarcodeScanningOptions
{
PossibleFormats=new List<ZXing.BarcodeFormat>
{
ZXing.BarcodeFormat.QR_CODE
}
};
scanPage = new ZXingScannerPage(opt);
}

catch (Exception ex) {
await DisplayAlert("xxx.com", ex.Message.ToString(), "OK");

}
scanPage.OnScanResult += (result) => {
scanPage.IsScanning = false;


Device.BeginInvokeOnMainThread (async() => {
string qrcode = result.Text.Replace("http://www.xxx.com/qr/", "");

//DisplayAlert("Scanned Barcode", result.Text, "OK");
IIC iic = new IIC();
string j = iic.GetChoices(qrcode);
Debug.WriteLine(j);
//DisplayAlert("xxx.com", j, "Ok");

if ((j == "null") || (string.IsNullOrEmpty(j)) || (j == ""))
{
//do something with empty
await DisplayAlert("Alert", "No choices for this code", "OK");
}
else
{
Newtonsoft.Json.Linq.JArray choices = Newtonsoft.Json.Linq.JArray.Parse(j);
//await DisplayAlert("xxx.com", choices.ToString(), "Ok");
cp = new Choices(choices);

//Device.BeginInvokeOnMainThread(() => {
//Navigation.PopAsync();
Navigation.RemovePage(scanPage);
await Navigation.PushAsync(cp); //});
}
//await DisplayAlert("xxx.com", iic.Scan(3), "Ok");
});
};

await Navigation.PushAsync (scanPage);

};

Reply all
Reply to author
Forward
0 new messages