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); } }