public void ScanContinuously(MobileBarcodeScanningOptions options, bool useAVCaptureEngine, Action <Result> scanHandler) { try { Version sv = new Version(0, 0, 0); Version.TryParse(UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) { allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); } this.appController.InvokeOnMainThread(() => { //if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) //{ // viewController = new AVCaptureScannerViewController(options, this); // viewController.ContinuousScanning = true; //} //else //{ //if (useAVCaptureEngine && !is7orgreater) // Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); //else if (useAVCaptureEngine && !allRequestedFormatsSupported) //Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); viewController = new CustomScannerViewController(options, new MobileBarcodeScanner()) { ContinuousScanning = true }; //} viewController.OnScannedResult += barcodeResult => { // If null, stop scanning was called if (barcodeResult == null) { ((UIViewController)viewController).InvokeOnMainThread(() => { ((UIViewController)viewController).DismissViewController(true, null); }); } scanHandler(barcodeResult); }; appController.PresentViewController((UIViewController)viewController, true, null); }); } catch (Exception ex) { Console.WriteLine(ex); } }
public void ScanContinuously (MobileBarcodeScanningOptions options, bool useAVCaptureEngine, Action<Result> scanHandler) { try { Version sv = new Version (0, 0, 0); Version.TryParse (UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); this.appController.InvokeOnMainThread(() => { if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) { viewController = new AVCaptureScannerViewController(options, this); viewController.ContinuousScanning = true; } else { if (useAVCaptureEngine && !is7orgreater) Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); else if (useAVCaptureEngine && !allRequestedFormatsSupported) Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); viewController = new ZXing.Mobile.ZXingScannerViewController(options, this); viewController.ContinuousScanning = true; } viewController.OnScannedResult += barcodeResult => { // If null, stop scanning was called if (barcodeResult == null) { ((UIViewController)viewController).InvokeOnMainThread(() => { ((UIViewController)viewController).DismissViewController(true, null); }); } scanHandler (barcodeResult); }; appController.PresentViewController((UIViewController)viewController, true, null); }); } catch (Exception ex) { Console.WriteLine(ex); } }
partial void UIButton197_TouchUpInside(UIButton sender) { try { // CODE to get current view controller foreach (var window in UIApplication.SharedApplication.Windows) { if (window.RootViewController != null) { appController = window.RootViewController; break; } } viewController = new CustomScannerViewController(new MobileBarcodeScanningOptions(), new MobileBarcodeScanner()); appController.PresentViewController((UIViewController)viewController, true, null); viewController.OnScannedResult += barcodeResult => { ((UIViewController)viewController).InvokeOnMainThread(() => { viewController.Cancel(); // Handle error situation that occurs when user manually closes scanner in the same moment that a QR code is detected try { ((UIViewController)viewController).DismissViewController(true, () => { //HandleScanResult(barcodeResult); }); } catch (ObjectDisposedException) { // In all likelihood, iOS has decided to close the scanner at this point. But just in case it executes the // post-scan code instead, set the result so we will not get a NullReferenceException. //HandleScanResult(barcodeResult); } }); HandleScanResult(barcodeResult); }; } catch (Exception ex) { Console.WriteLine("EXCEPTION- " + ex.Message); } }
public Task<Result> Scan (MobileBarcodeScanningOptions options, bool useAVCaptureEngine) { return Task.Factory.StartNew(() => { try { scanResultResetEvent.Reset(); Result result = null; Version sv = new Version (0, 0, 0); Version.TryParse (UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); this.appController.InvokeOnMainThread(() => { if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) { viewController = new AVCaptureScannerViewController(options, this); } else { if (useAVCaptureEngine && !is7orgreater) Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); else if (useAVCaptureEngine && !allRequestedFormatsSupported) Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); viewController = new ZXing.Mobile.ZXingScannerViewController(options, this); } viewController.OnScannedResult += barcodeResult => { ((UIViewController)viewController).InvokeOnMainThread(() => { viewController.Cancel(); ((UIViewController)viewController).DismissViewController(true, () => { result = barcodeResult; scanResultResetEvent.Set(); }); }); }; appController.PresentViewController((UIViewController)viewController, true, null); }); scanResultResetEvent.WaitOne(); ((UIViewController)viewController).Dispose(); return result; } catch (Exception ex) { Console.WriteLine(ex); return null; } }); }
public Task <Result> Scan(MobileBarcodeScanningOptions options, bool useAVCaptureEngine) { return(Task.Factory.StartNew(() => { try { scanResultResetEvent.Reset(); Result result = null; Version sv = new Version(0, 0, 0); Version.TryParse(UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) { allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); } this.appController.InvokeOnMainThread(() => { if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) { viewController = new AVCaptureScannerViewController(options, this); } else { if (useAVCaptureEngine && !is7orgreater) { Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); } else if (useAVCaptureEngine && !allRequestedFormatsSupported) { Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); } viewController = new ZXing.Mobile.ZXingScannerViewController(options, this); } viewController.OnScannedResult += barcodeResult => { ((UIViewController)viewController).InvokeOnMainThread(() => { viewController.Cancel(); ((UIViewController)viewController).DismissViewController(true, () => { result = barcodeResult; scanResultResetEvent.Set(); }); }); }; appController.PresentViewController((UIViewController)viewController, true, null); }); scanResultResetEvent.WaitOne(); ((UIViewController)viewController).Dispose(); return result; } catch (Exception ex) { Console.WriteLine(ex); return null; } })); }
public Task <Result> Scan(MobileBarcodeScanningOptions options, bool useAVCaptureEngine) { return(Task.Factory.StartNew(() => { try { scanResultResetEvent.Reset(); Result result = null; Version sv = new Version(0, 0, 0); Version.TryParse(UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) { allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); } this.appController.InvokeOnMainThread(() => { if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) { viewController = new AVCaptureScannerViewController(options, this); } else { if (useAVCaptureEngine && !is7orgreater) { Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); } else if (useAVCaptureEngine && !allRequestedFormatsSupported) { Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); } viewController = new ZXing.Mobile.ZXingScannerViewController(options, this); } viewController.OnScannedResult += barcodeResult => { ((UIViewController)viewController).InvokeOnMainThread(() => { viewController.Cancel(); // Handle error situation that occurs when user manually closes scanner in the same moment that a QR code is detected try { ((UIViewController)viewController).DismissViewController(true, () => { result = barcodeResult; scanResultResetEvent.Set(); }); } catch (ObjectDisposedException) { // In all likelihood, iOS has decided to close the scanner at this point. But just in case it executes the // post-scan code instead, set the result so we will not get a NullReferenceException. result = barcodeResult; scanResultResetEvent.Set(); } }); }; appController.PresentViewController((UIViewController)viewController, true, null); }); scanResultResetEvent.WaitOne(); ((UIViewController)viewController).Dispose(); return result; } catch (Exception ex) { Console.WriteLine(ex); return null; } })); }
public Task<Result> Scan (MobileBarcodeScanningOptions options, bool useAVCaptureEngine) { return Task.Factory.StartNew(() => { try { scanResultResetEvent.Reset(); Result result = null; Version sv = new Version (0, 0, 0); Version.TryParse (UIDevice.CurrentDevice.SystemVersion, out sv); var is7orgreater = sv.Major >= 7; var allRequestedFormatsSupported = true; if (useAVCaptureEngine) allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats); this.appController.InvokeOnMainThread(() => { if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported) { viewController = new AVCaptureScannerViewController(options, this); } else { if (useAVCaptureEngine && !is7orgreater) Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead"); else if (useAVCaptureEngine && !allRequestedFormatsSupported) Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead"); viewController = new ZXing.Mobile.ZXingScannerViewController(options, this); } viewController.OnScannedResult += barcodeResult => { ((UIViewController)viewController).InvokeOnMainThread(() => { viewController.Cancel(); // Handle error situation that occurs when user manually closes scanner in the same moment that a QR code is detected try { ((UIViewController) viewController).DismissViewController(true, () => { result = barcodeResult; scanResultResetEvent.Set(); }); } catch (ObjectDisposedException) { // In all likelihood, iOS has decided to close the scanner at this point. But just in case it executes the // post-scan code instead, set the result so we will not get a NullReferenceException. result = barcodeResult; scanResultResetEvent.Set(); } }); }; appController.PresentViewController((UIViewController)viewController, true, null); }); scanResultResetEvent.WaitOne(); ((UIViewController)viewController).Dispose(); return result; } catch (Exception ex) { Console.WriteLine(ex); return null; } }); }