Download the demo project and extract it, then open this project using Visual Studio.
Modify the MainPage.xaml.cs to specify your region, cardType, cardSide, and license(The license content is obtained by your server calling our openapi).
// Specify your regin, cardType, cardSide:
// region: Regional ISO code, you can use 2-digit or 3-digit shortcode, see Wikipedia https://zh.wikipedia.org/wiki/ISO_3166-1// cardType: IDCARD, DRIVINGLICENSE, UMID, SSS, TIN, PASSPORT, VOTERID, NATIONALID, PRC, POSTALID, PAGIBIG// cardSide: FRONT, BACKiqc.initSDK("ID", "IDCARD", "FRONT");
// Specify license. The license content is obtained by your server calling our openapivar license = "your-license";var resultStr = iqc.setLicenseAndCheck(license);Run project XamarinFormsIQCDemo.iOS on your iPhone device.
Integrate the SDK into your project:
NuGet source https://public-n3.advai.net/repository/nuget-hosted/.AdvanceAI.iOS.IQC.Add camera usage description in Info.plist as bellow. Ignore this step if you have added those.
<key>NSCameraUsageDescription</key><string>Use the camera to detect the card</string>New interface IIQCService.cs to your XamarinForms project:
using System;namespace AdvanceAI.iOS.IQC.Services{ public class Result { public bool isSucceed; public String base64Image; public String IDVID; public String pictureType;
public String transactionId; public String errorCode; public String errorMsg; }
public interface IIQCService { void initSDK(String region, String cardType, String cardSide); String setLicenseAndCheck(String license); void showIQCPage(Action<Result> resultCallback); }}New IOSIQCService.cs to your XamarinForms.iOS project:
using System;using AdvanceAI.iOS.IQC.Services;
[assembly: Xamarin.Forms.Dependency(typeof(AdvanceAI.iOS.IQC.Services.IOSIQCService))]namespace AdvanceAI.iOS.IQC.Services{ using AdvanceAI.iOS.IQC; using Foundation; using UIKit;
public class IOSIQCService: AAIGlobalIQADelegate, IIQCService { private Action<Result> mResultCallback;
public IOSIQCService() { }
public void initSDK(string region, string cardType, string cardSide) { var rawCardType = AAIIQACardType.IDCard; switch (cardType.ToUpper()) { case "IDCARD": rawCardType = AAIIQACardType.IDCard; break; case "DRIVINGLICENSE": rawCardType = AAIIQACardType.DrivingLicense; break; case "UMID": rawCardType = AAIIQACardType.Umid; break; case "SSS": rawCardType = AAIIQACardType.Sss; break; case "TIN": rawCardType = AAIIQACardType.Tin; break; case "PASSPORT": rawCardType = AAIIQACardType.Passport; break; case "VOTERID": rawCardType = AAIIQACardType.Voterid; break; case "NATIONALID": rawCardType = AAIIQACardType.Nationalid; break; case "PRC": rawCardType = AAIIQACardType.Prc; break; case "POSTALID": rawCardType = AAIIQACardType.Postalid; break; case "PAGIBIG": rawCardType = AAIIQACardType.Pagibig; break; default: break; }
var rawCardSide = AAIIQACardSide.Front; if (cardSide.ToUpper() == "FRONT") { rawCardSide = AAIIQACardSide.Front; } else { rawCardSide = AAIIQACardSide.Back; } AAIGlobalIQAConfig config = AAIGlobalIQAConfig.InitWithRegion(region, rawCardType, rawCardSide); config.Delegate = this; config.CallbackAfterPageDismissed = true; // If you want to do additional settings, // please refer to the native sdk documentation // https://doc.advance.ai/sdk/ios/global-iqc/en/standard.html
AAIGlobalIQASDK.InitWithConfig(config); }
public override void IqaOnDetectionComplete(AAIGlobalIQAResult result) { var callbackResult = new Result(); callbackResult.isSucceed = result.Success; callbackResult.transactionId = result.TransactionId; if (result.Success) { callbackResult.IDVID = result.IDVID; callbackResult.base64Image = result.CardImg.AsJPEG(1).GetBase64EncodedString(NSDataBase64EncodingOptions.None); callbackResult.pictureType = result.PictureType; } else { callbackResult.errorCode = result.ErrorCode; callbackResult.errorMsg = result.ErrorMsg; }
// Callback mResultCallback(callbackResult); }
public string setLicenseAndCheck(string license) { return AAIGlobalIQASDK.SetLicenseAndCheck(license); }
public void showIQCPage(Action<Result> resultCallback) { mResultCallback = resultCallback;
var keyWindow = UIApplication.SharedApplication.KeyWindow; var rootVC = keyWindow.RootViewController; AAIGlobalIQASDK.StartWithRootVC(rootVC); } }}In your XamarinForms project, specify your region, cardType, cardSide, and license content, then show SDK page :
void Button_Clicked(System.Object sender, System.EventArgs e){ if (DeviceInfo.Platform == DevicePlatform.iOS) { // Show iOS IQC page showIQCPage(); } else if (DeviceInfo.Platform == DevicePlatform.Android) { // Show android IQC page Console.WriteLine("TODO: Show android IQC page....."); }}
void showIQCPage(){ var iqc = Xamarin.Forms.DependencyService.Get<IIQCService>();
// Specify your regin, cardType, cardSide:
// region: Regional ISO code, you can use 2-digit or 3-digit shortcode, see Wikipedia https://zh.wikipedia.org/wiki/ISO_3166-1 // cardType: IDCARD, DRIVINGLICENSE, UMID, SSS, TIN, PASSPORT, VOTERID, NATIONALID, PRC, POSTALID, PAGIBIG // cardSide: FRONT, BACK iqc.initSDK("ID", "IDCARD", "FRONT");
// Specify license. The license content is obtained by your server calling our openapi var license = "your-license"; var resultStr = iqc.setLicenseAndCheck(license); if (resultStr == "SUCCESS") { iqc.showIQCPage((result) => {
if (result.isSucceed) { var str = String.Format("Detection succeed! IDVID:{0}", result.IDVID); Console.WriteLine(str); } else { var str = String.Format("Detection failed! errorCode: {0}. errorMsg: {1}. transactionId: {2}", result.errorCode, result.errorMsg, result.transactionId); Console.WriteLine(str); } });
} else { var str = String.Format("License check failed: {0}", resultStr); Console.WriteLine(str); }}The errorCode values of Result are as follows:
| Name | Description |
|---|---|
| USER_GIVE_UP | User tapped the back button |
| DEVICE_NOT_SUPPORT | This device is not supported |
| CAMERA_PERMISSION_DENIED | Permission to access the camera is not authorized |
| NETWORK_REQUEST_FAILED | Network request failed |
| CAMERA_OPEN_FAILED | Failed to open camera |
| MODEL_ERROR | Load model failed |
| SCAN_TIMEOUT | Scan timeout. Note this code appears only when you set the OperatingMode of AAIGlobalIQAConfig to "AAIIQAOperatingMode.Scanning". (This code avaliable on 1.2.0 or higher) |
| Other error code | See document |