private void InitializeAnyline() { NSError error = null; if (initialized) { return; } try { frame = View.Bounds; string configurationFile = (Element as ScanExamplePage).ConfigurationFile.Replace(".json", ""); // Use the JSON file name that you want to load here var configPath = NSBundle.MainBundle.PathForResource(configurationFile, @"json"); // This is the main intialization method that will create our use case depending on the JSON configuration. _resultDelegate = new ScanResultDelegate((Element as ScanExamplePage).ShowResultsAction); _scanView = ALScanView.ScanViewForFrame(frame, configPath, licenseKey, _resultDelegate, out error); if (error != null) { throw new Exception(error.LocalizedDescription); } // KNOWN ISSUE: the result delegate has to be added specifically to the scan plugin. // this should be automatically done already with the ScanViewForFrame call. ConnectDelegateToScanPlugin(); View.AddSubview(_scanView); _scanView.StartCamera(); initialized = true; } catch (Exception e) { ShowAlert("Init Error", e.Message); } }
private void InitializeAnyline() { NSError error = null; if (_initialized) { return; } try { _frame = UIScreen.MainScreen.ApplicationFrame; _frame = new CGRect(_frame.X, _frame.Y + NavigationController.NavigationBar.Frame.Size.Height, _frame.Width, _frame.Height - NavigationController.NavigationBar.Frame.Size.Height); // Use the JSON file name that you want to load here var configPath = NSBundle.MainBundle.PathForResource(@"" + _jsonPath.Replace(".json", ""), @"json"); // This is the main intialization method that will create our use case depending on the JSON configuration. //_scanView = ALScanView.ScanViewForFrame(_frame, configPath, LicenseKey, _resultDelegate, out error); _scanView = ALScanView.ScanViewForFrame(_frame, configPath, LicenseKey, Self, out error); if (error != null) { throw new Exception(error.LocalizedDescription); } // KNOWN ISSUE (OCRScanPlugin only): the customCmdFile is not loading the file correctly. therefore, it has to be added via code: if (_scanView.ScanViewPlugin is ALOCRScanViewPlugin) { var file = File.ReadAllText(configPath); NSData data = NSData.FromString(file); NSDictionary dict = NSJsonSerialization.Deserialize(data, 0, out error) as NSDictionary; var customCmdFileName = dict.ValueForKeyPath(new NSString(@"viewPlugin.plugin.ocrPlugin.customCmdFile")); if (customCmdFileName != null) { var name = customCmdFileName.ToString().Split('.'); if (name.Length == 2) { var config = (_scanView.ScanViewPlugin as ALOCRScanViewPlugin).OcrScanPlugin.OcrConfig; config.CustomCmdFilePath = NSBundle.MainBundle.PathForResource(name[0], name[1]); // explicitly call this method so everything is updated internally (_scanView.ScanViewPlugin as ALOCRScanViewPlugin).OcrScanPlugin.SetOCRConfig(config, out error); if (error != null) { ShowAlert("OCR Config Error", error.DebugDescription); } } } } // KNOWN ISSUE: the result delegate has to be added specifically to the scan plugin. // this should be automatically done already with the ScanViewForFrame call. ConnectDelegateToScanPlugin(); View.AddSubview(_scanView); _scanView.StartCamera(); _initialized = true; } catch (Exception e) { ShowAlert("Init Error", e.Message); } }
public override void ViewDidLoad() { base.ViewDidLoad(); float hintMargin = 2; // Set the background color to black to have a nicer transition View.BackgroundColor = UIColor.Black; UILabel hintViewLabel = new UILabel(CGRect.Empty); hintView = new UIView(CGRect.Empty); hintViewLabel.Text = @"Scan MRZ"; hintViewLabel.SizeToFit(); hintView.AddSubview(hintViewLabel); hintView.Frame = new UIEdgeInsets(hintViewLabel.Frame.Top, hintViewLabel.Frame.Left, hintViewLabel.Frame.Bottom, hintViewLabel.Frame.Right) .InsetRect(new CGRect(-hintMargin, -hintMargin, -hintMargin, -hintMargin)); hintView.Center = new CGPoint(View.Center.X, 0); hintViewLabel.TranslatesAutoresizingMaskIntoConstraints = false; hintViewLabel.CenterYAnchor.ConstraintEqualToSystemSpacingBelowAnchor(hintView.CenterYAnchor, 0); hintViewLabel.CenterXAnchor.ConstraintEqualToSystemSpacingAfterAnchor(hintView.CenterXAnchor, 0); hintView.Layer.CornerRadius = 8; hintView.Layer.MasksToBounds = true; hintView.BackgroundColor = UIColor.Black.ColorWithAlpha(0.5f); hintViewLabel.TextColor = UIColor.White; View.AddSubview(hintView); ALMRZConfig mrzConfig = new ALMRZConfig(); //we want to be quite confident of these fields to ensure we can read the NFC with them ALMRZFieldConfidences fieldConfidences = new ALMRZFieldConfidences(); fieldConfidences.DocumentNumber = 90; fieldConfidences.DateOfBirth = 90; fieldConfidences.DateOfExpiry = 90; mrzConfig.IdFieldConfidences = fieldConfidences; //Create fieldScanOptions to configure individual scannable fields ALMRZFieldScanOptions scanOptions = new ALMRZFieldScanOptions(); scanOptions.VizAddress = ALFieldScanOption.Default; scanOptions.VizDateOfIssue = ALFieldScanOption.Default; scanOptions.VizSurname = ALFieldScanOption.Default; scanOptions.VizGivenNames = ALFieldScanOption.Default; scanOptions.VizDateOfBirth = ALFieldScanOption.Default; scanOptions.VizDateOfExpiry = ALFieldScanOption.Default; //Set scanOptions for MRZConfig mrzConfig.IdFieldScanOptions = scanOptions; NSError error = null; //Init the anyline ID ScanPlugin with an ID, Licensekey, the delegate, // the MRZConfig (which will configure the scan Plugin for MRZ scanning), and an error this.mrzScanPlugin = new ALIDScanPlugin(@"ModuleID", AnylineViewController.LicenseKey, this, mrzConfig, out error); nfcDetector = new ALNFCDetector(AnylineViewController.LicenseKey, this); mrzScanViewPlugin = new ALIDScanViewPlugin(mrzScanPlugin); var frame = UIScreen.MainScreen.ApplicationFrame; frame = new CGRect(frame.X, frame.Y + NavigationController.NavigationBar.Frame.Size.Height, frame.Width, frame.Height - NavigationController.NavigationBar.Frame.Size.Height); // This is the main intialization method that will create our use case depending on the JSON configuration. scanView = new ALScanView(frame, mrzScanViewPlugin); scanView.ScanViewPlugin.AddScanViewPluginDelegate(new CutoutListener(updateHintPosition, scanView)); scanView.FlashButtonConfig.FlashAlignment = ALFlashAlignment.TopLeft; // After setup is complete we add the scanView to the view of this view controller View.AddSubview(scanView); View.SendSubviewToBack(scanView); var topGuide = TopLayoutGuide; var viewNames = NSDictionary.FromObjectsAndKeys(new object[] { scanView, topGuide, }, new NSObject[] { new NSString("scanView"), new NSString("topGuide"), }); var emptyDict = new NSDictionary(); View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[scanView]|", 0, emptyDict, viewNames)); View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[topGuide]-0-[scanView]|", 0, emptyDict, viewNames)); scanView.StartCamera(); }