MonoTouch, ZXing: ZXingScannerViewController view failed

So, at the beginning of my application, users have the ability to scan a QR code. In the application settings, the user can scan another barcode to change some data in the settings.

At the beginning of my application, the scanner works fine, but when I try to scan the barcode in the VC settings, I get the following warning:

Warning: Attempt to present ZXing.Mobile.ZXingScannerViewController: 0x18036dc0 on UINavigationController: 0x16d8afe0 whose view is not in the window hierarchy! 

I already tried to call the viewDidAppear check, but I get the same warning.

  button_ScanAPI.TouchUpInside += async (sender, e) => { var scanner = new ZXing.Mobile.MobileBarcodeScanner (); var result = await scanner.Scan (); if (result != null) { textField_APIKey.Text = result.Text; } }; 

EDIT:

I tried using a barcode scanner without async, but I still get the same msg.

 var scanner = new ZXing.Mobile.MobileBarcodeScanner (); scanner.Scan (true).ContinueWith (t => { if (t.Result != null) { InvokeOnMainThread (() => { textField_APIKey.Text = t.Result.Text; }); } }); 

And I also tried using AVFoundation, which led to the same error:

 Warning: Attempt to present <AVCaptureScannerViewController: 0x16fb1d00> on <UINavigationController: 0x16ebe790> whose view is not in the window hierarchy! 

EDIT2:

This is part of the stream in my application.

enter image description here

+6
source share
3 answers

So, you can scan the QR natively. In iOS 7, AVFoundation is able to scan QR. Take a look at the doc .

And here is an example of using Xamarin.

+1
source

I think that by default, the ZXing library should look for your highest level NavigationController and try to display the modal view controller here. Like you, I modeled another navigation controller over the top of the root. I was able to fix this by changing the constructor to:

 var scanner = new MobileBarcodeScanner (this); var result = await scanner.Scan (); 

where "this" is the ViewController from which you are actually invoking the scanner.

+5
source

Do one of these:

  • Show settingsVC without animation, i.e. from VC, which represents settingsVC :

     [self presentViewController:settingsVC animated:NO completion:nil]; 

    or

     [self.navigationController pushViewController:settingsVC animated:NO]; 
  • Use the delay before showing the scanner, for example. in settingsVC :

     - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSTimeInterval delay = 0.3; [self performSelector:@selector(showScanner) withObject:nil afterDelay:delay]; } - (void)showScanner { // Show scanner here. } 
0
source

All Articles