Skip to main content
Version: 2.5.2

Integration in a Xamarin project

Brief

The smart scanner library have to be integrated first into a native binding project (with its dependencies) before being added into the project where you want to use it.

This integration guide has been done using the xamarin for mac 7.7.3. Using Xcode 10.1.

This guide has mainly been done by following the official xamarin documentation. You're encouraged to also check for information on the official guide.

Requirements

  1. Icare SmartScan framework That you should already got from us.
  2. OpenCV framework for iOS (We're currently using the version 3.2.0 but refer to smartscan documentation). Download page.
  3. Objective sharpie. Which is a tool provided by Microsoft to create binding between iOS Native code and c# Download page.

Integration

In Terminal

After downloading and installing Objective sharpie. You need to generate the files needed to bind the library to c#. This can be done simply by using the following command in the terminal

sharpie bind -output SmartScanLib -namespace SmartScanLib -sdk iphoneos12.1 SmartIDScanner.framework/Headers/SmartIDScanner.h -scope SmartIDScanner.framework/Headers/

with

output : output folder namespace : the namespace that will be generated in the files sdk : one of your availabled SDK. You can get the list using the command "sharpie xcode -sdks" scope : limit the generation to only the files in the framework. (necessary to not have sharpie generate binding for the full iOS framework) input file : the main .h file in the library

This step will generate 2 files. One for structures and enums used in the library, the other one for the methods and attributes exposed in the library.

In Xamarin
  1. In your solution add a new project of type "Bindings Library" (in iOS -> Library)

  2. In that new project, add OpenCV and SmartScan Framework as native reference

  3. Copy the content of the two file generated in the terminal into Structs.cs and ApiDefinition.cs

  4. The file generation will output some [VERIFY] tags. That means you have to check the types a do to get them working. Here are some common changes you might have to do :

    • replace NSUINT with uint
    • comment out the interface constants. Mainly the one returning a byte array
  5. Configure xamarin to handle the framework correctly. Right click the library -> property :

    1. For opencv2 : The framework should be specified as c++, force-load, and smart-link
    2. SmartIDScanner : force-load, smart-link and you should also add the following weak framework : "CoreMedia CoreVideo AVFoundation CoreGraphics Foundation QuartzCore CoreImage"
  6. You might now Integrate the binding library, in your other projects. as a reference.

  7. You'll need to edit the Info.plist and add a description about why you're using the camera. Or the app will crash the moment you start the library.

    <key>NSCameraUsageDescription</key>
    <string>Used to decode QRCodes</string>

Use

You can translate the code from the AppSample with your library. Or just a quick test you can juste integrate in one your view controller the following code.

First be sure to implement that your viewcontroller in implementing the interface ISmartScannerDelegate

Then, for example in the viewDidLayoutSubview, you can copy past

 SmartScanner _sc;

...

_sc = new SmartScanner();
UIView v = _sc.PreviewViewWithViewSize(this.View.Bounds, SmartScannerQuality.Normal);
this.View.AddSubview(v);
_sc.SetDecodingType(SmartDecodingTypes.Ocrb, SmartDecodingSubTypes.Icao9303Idcard);
_sc.WeakScDelegate = this;
CGRect sizes = new CGRect(10, 10, 620, 460);
_sc.SetRegionOfInterest(sizes);

Note that this code is not "clean". You should follow the indications in the iOS Documentation.