Advanced Topics

This section covers detailed topics about the Anyline SDK Plugin on Xamarin. You will not require knowledge about these advanced topics in your every day use of the SDK. However, in case you need specific information about certain topics in the Anyline SDK, it will be covered here.

Camera2 API - Enable hardware acceleration

In the Xamarin.Android quickstart guide it is described what features and permissions the AndroidManifest.XML should contain. Newer devices might use the new Camera2 API, therefore hardware acceleration must be enabled in the activity that renders the camera. Depending on the device, it might not be enough to add a android:hardwareAccelerated="true" property in the <application> tag in AndroidManifest.XML. So if the camera screen stays black, it’s necessary to set the hardware acceleration directly in C#.

[Activity(Label = "My Activity", HardwareAccelerated = true, ...)]
public class MainActivity : Activity, IBarcodeResultListener // ...
{
    ...
}

NFC Reader - iOS

NFC Reader can only be used to scan passports on the iPhones from model 7 and up, running iOS 13 and up. A full example implementation is available in our Xamarin.Forms Example App on GitHub. To use the NFC reader, Apple requires that the project includes a specific Entitlements.plist file and is signed with a Provisioning Profile with NFC capability (note that Wildcard Provisioning Profiles cannot be used when signing projects with NFC capability). To create the required files, access the Apple developer portal and do the following:

  1. Create your Development Certificate
  2. Download the certificate and install it on your Mac host
  3. Create an App Identifier for your specific Bundle ID, with NFC Tag Reading capability
  4. Create a Provisioning Profile linked with your previously created Certificate and App Identifier
  5. Download the Provisioning Profile and install it on your Mac host

In the Xamarin.iOS examples app we provide an Entitlements.plist file which is not referenced in the project. To start using the NFC reader follow these steps:

  1. Open the examples app solution in Visual Studio
  2. Right-click in the AnylineExamples.iOS project > Properties
  3. In the iOS Bundle Signing tab, find the Custom Entitlements field
  4. Select the file Entitlements.plist, located in the root of the iOS project
  5. In Signing Identity and Provisioning Profile select the certificate and profile created in the Apple developer portal
  6. Save the changes
iOS - Signing and Entitlements

Error messages

"codesign" exited with code 1.: Make sure that every time you change your signing configuration (Certificate, Provisioning Profile, Entitlements) you also erase the bin/obj folders before running the project. (The executable was signed with invalid entitlements.): Your Provisioning Profile does not contains NFC capability and cannot be used with the Entitlements.plist file. NFC Not Supported - NFC is not supported on this device: Make sure your device is compatible with NFC reading and you are referencing the right Certificate, Provisioning Profile and Entitlements.plist file in the project properties.

NFC Reader - Android

Starting with Anyline 33 it is possible to read NFC Chips of Passports also on Xamarin Android. A full example implementation is available in our Xamarin.Forms Example App on GitHub. Android does not require as many configuration changes as iOS. You will just need to:

  1. Add to your “AndroidManifest.xml” file the NFC Permission <uses-permission android:name="android.permission.NFC" />
  2. Add to your “AndroidManifest.xml” file the NFC Feature <uses-feature android:name="android.hardware.nfc" android:required="false" />
  3. Add a new Activity (Project > Add > New File > Android Activity) which will be responsible for receiving the NFC Tag events, and a xml Layout to provide feedback to your app’s users
  4. If you are using Xamarin Forms, use a standard ScanPageRenderer for scanning the MRZ data
  5. Use the passport string from the MRZ Scan to unlock the NFC chip, inside the NFCScanActivity

Face Image - Android

To obtain the Face Image while scanning with the Universal ID scan mode, add the following dependencies to your Android project:

When using Universal ID: In your id_config_universal.json file, inside the “universalIdConfig” property, add the property "faceDetection":true. When using the MRZ Scanner: In your ScanActivity.cs file, set “EnableFaceDetection(true);” in the MrzConfig.

Erase the bin and obj folders and rebuild your project.

Face Image - iOS

When using Universal ID: In your id_config_universal.json file, inside the “universalIdConfig” property, add the property "faceDetection":true. When using the MRZ Scanner the Face Image will be returned by default.

Barcode - Android

When using the default Barcode scanner, the Xamarin.Android project may throw issues similar to this one: Unhandled Exception:Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/google/mlkit/vision/barcode/BarcodeScannerOptions$Builder

If that happens in your Xamarin.Android project, please follow these instructions:

  • Target the Android 9.0 (API 28) on the project Properties (Application and Manifest)
  • Add the NuGet package Xamarin.Google.MLKit.BarcodeScanning to the project
  • In your barcode.json configuration file, remove the “barcodeFormatOptions” attribute, so that the ‘ “barcodePlugin”: { } ‘ is empty
  • Erase the bin and obj folders and rebuild your project