Advanced Topics
Xamarin End of Life Announcement
Anyline has been a longstanding provider of the Mobile SDK for Xamarin, catering to developers' needs for several years. As of autumn 2022, we have seamlessly transitioned our support to encompass the SDK for .NET (MAUI), recognized as the official successor to Xamarin. In alignment with Microsoft’s recommendation to migrate from Xamarin to .NET, and considering Microsoft’s cessation of support for Xamarin by May 2024, Anyline will discontinue the release of any additional updates, including new features or bug fixes, for Anyline Mobile SDK for Xamarin. Please find the Anyline Mobile SDK for .NET here. |
This section covers detailed topics about the Anyline SDK 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
{
...
}
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:
-
Create your Development Certificate
-
Download the certificate and install it on your Mac host
-
Create an App Identifier for your specific Bundle ID, with
NFC Tag Reading capability
-
Create a Provisioning Profile linked with your previously created Certificate and App Identifier
-
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:
-
Open the examples app solution in Visual Studio
-
Right-click in the
AnylineExamples.iOS
project > Properties -
In the
iOS Bundle Signing
tab, find theCustom Entitlements
field -
Select the file
Entitlements.plist
, located in the root of the iOS project -
In
Signing Identity
andProvisioning Profile
select the certificate and profile created in the Apple developer portal -
Save the changes
Error Messages
|
NFC Reader - 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:
-
Add to your
AndroidManifest.xml
file the NFC Permission<uses-permission android:name="android.permission.NFC" />
-
Add to your
AndroidManifest.xml
file the NFC Feature<uses-feature android:name="android.hardware.nfc" android:required="false" />
-
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
-
If you are using Xamarin Forms, first, use a standard ScanPageRenderer for scanning the MRZ data
-
Use the passport string from the MRZ Scan to unlock the NFC chip, inside the NFCScanActivity
Face Image
To obtain the Face Image while scanning IDs, do the following:
-
Universal ID: In your JSON config file, inside the
universalIdConfig
property, add the boolean property:"faceDetectionEnabled": true
. -
MRZ: In your JSON config file, inside the
mrzConfig
property, add the boolean property:"faceDetectionEnabled": true
.
Android
On Android, to scan the Face Image you will also have to target at least Android v12, add a few dependencies to your project.
-
Target the Android 12.0 (API 31) on the project Properties (Application and Manifest)
-
Add the following NuGet package dependencies to your Android project:
-
Erase the bin and obj folders and rebuild your project.
Barcode - Android
When using the legacy 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 12.0 (API 31) on the project Properties (Application and Manifest)
-
Add the NuGet package Xamarin.Google.MLKit.BarcodeScanning to the project
-
Erase the bin and obj folders and rebuild your project