From 149696a110ddc40063af2dfbe3729e76f670bc9a Mon Sep 17 00:00:00 2001
From: igor-graca <80965280+igor-graca@users.noreply.github.com>
Date: Fri, 6 Sep 2024 12:54:02 +0200
Subject: [PATCH] Release 9.0.0 (#9)
---
MAUI/Anyline.Examples.MAUI.csproj | 18 +-
MAUI/MainPage.xaml.cs | 10 +-
MAUI/MauiProgram.cs | 4 -
MAUI/Models/AnylineScanModes.cs | 5 -
MAUI/NFC/MyNFCScanningWithAnylinePage.xaml | 11 -
MAUI/NFC/MyNFCScanningWithAnylinePage.xaml.cs | 74 -------
MAUI/NFC/MyScanResults.cs | 45 ----
MAUI/NFC/NFCResultsPage.xaml | 75 -------
MAUI/NFC/NFCResultsPage.xaml.cs | 42 ----
MAUI/NFC/NFCScanExampleView.cs | 40 ----
MAUI/Platforms/Android/AndroidManifest.xml | 4 +-
MAUI/Platforms/Android/NFC/NFCScanActivity.cs | 197 ------------------
.../Android/NFC/NFCScanningViewRenderer.cs | 191 -----------------
.../Android/Resources/layout/ActivityNFC.xml | 59 ------
MAUI/Platforms/iOS/Entitlements.plist | 5 -
MAUI/Platforms/iOS/Info.plist | 6 -
.../iOS/NFC/NFCScanningViewRenderer.cs | 191 -----------------
17 files changed, 5 insertions(+), 972 deletions(-)
delete mode 100644 MAUI/NFC/MyNFCScanningWithAnylinePage.xaml
delete mode 100644 MAUI/NFC/MyNFCScanningWithAnylinePage.xaml.cs
delete mode 100644 MAUI/NFC/MyScanResults.cs
delete mode 100644 MAUI/NFC/NFCResultsPage.xaml
delete mode 100644 MAUI/NFC/NFCResultsPage.xaml.cs
delete mode 100644 MAUI/NFC/NFCScanExampleView.cs
delete mode 100644 MAUI/Platforms/Android/NFC/NFCScanActivity.cs
delete mode 100644 MAUI/Platforms/Android/NFC/NFCScanningViewRenderer.cs
delete mode 100644 MAUI/Platforms/Android/Resources/layout/ActivityNFC.xml
delete mode 100644 MAUI/Platforms/iOS/NFC/NFCScanningViewRenderer.cs
diff --git a/MAUI/Anyline.Examples.MAUI.csproj b/MAUI/Anyline.Examples.MAUI.csproj
index b7c68c9..860c23f 100644
--- a/MAUI/Anyline.Examples.MAUI.csproj
+++ b/MAUI/Anyline.Examples.MAUI.csproj
@@ -18,7 +18,7 @@
9C37433F-9192-4C96-B49A-B9A7E047FBC2
- 8.1.0
+ 9.0.0
1
12.0
@@ -70,18 +70,15 @@
-
-
-
-
-
+
+
@@ -97,12 +94,6 @@
MSBuild:Compile
-
-
-
-
- MSBuild:Compile
-
@@ -116,9 +107,6 @@
-
-
-
diff --git a/MAUI/MainPage.xaml.cs b/MAUI/MainPage.xaml.cs
index 40ef362..c6bc7d8 100644
--- a/MAUI/MainPage.xaml.cs
+++ b/MAUI/MainPage.xaml.cs
@@ -1,5 +1,4 @@
using Anyline.Examples.MAUI.Models;
-using Anyline.Examples.MAUI.NFC;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.Shapes;
@@ -63,14 +62,7 @@ private async void BtScan_Clicked(object sender, EventArgs e)
AnylineScanMode scanMode = new AnylineScanMode(name_config[0], name_config[1], string.Empty);
- if (scanMode.Name == "Scan NFC of Passports")
- {
- await Navigation.PushAsync(new MyNFCScanningWithAnylinePage(scanMode));
- }
- else
- {
- await Navigation.PushAsync(new MyScanningWithAnylinePage(scanMode));
- }
+ await Navigation.PushAsync(new MyScanningWithAnylinePage(scanMode));
(sender as Button).IsEnabled = true;
}
diff --git a/MAUI/MauiProgram.cs b/MAUI/MauiProgram.cs
index 10aff04..870cd57 100644
--- a/MAUI/MauiProgram.cs
+++ b/MAUI/MauiProgram.cs
@@ -3,17 +3,14 @@
namespace Anyline.Examples.MAUI;
-using NFC;
using Views;
#if ANDROID
using Anyline.Examples.MAUI.Platforms.Android.CustomRenderers;
-using Anyline.Examples.MAUI.Platforms.Android.NFC;
#endif
#if IOS
using Anyline.Examples.MAUI.Platforms.iOS.CustomRenderers;
-using Anyline.Examples.MAUI.Platforms.iOS.NFC;
#endif
public static class MauiProgram
@@ -27,7 +24,6 @@ public static MauiApp CreateMauiApp()
{
//handlers.AddHandler(typeof(AnylineView), typeof(AnylineHandler));
handlers.AddHandler(typeof(AnylineScanningView), typeof(AnylineScanningViewRenderer));
- handlers.AddHandler(typeof(NFCScanExampleView), typeof(NFCScanningViewRenderer));
})
.ConfigureFonts(fonts =>
{
diff --git a/MAUI/Models/AnylineScanModes.cs b/MAUI/Models/AnylineScanModes.cs
index 70a5b51..46e6ecc 100644
--- a/MAUI/Models/AnylineScanModes.cs
+++ b/MAUI/Models/AnylineScanModes.cs
@@ -48,10 +48,6 @@ public static List GetAnylineScanModesGroupedList()
new AnylineScanMode("Serial Scanning (LPT - EU > DVL > VIN)","workflows_config_serial_scanning.json"),
new AnylineScanMode("Parallel Scanning (Meter / Serial Number)","workflows_config_parallel_scanning.json"),
new AnylineScanMode("Parallel - First Scan (VIN or Barcode)","workflows_config_parallel_first_scan.json")
- }),
- new AnylineScanModeGroup("NFC", new List
- {
- new AnylineScanMode("Scan NFC of Passports","id_config_mrz.json")
})
};
}
@@ -71,7 +67,6 @@ public class AnylineScanMode
{
public string Name { get; set; }
public string JSONConfigPath { get; set; }
- public bool IsNFC { get; set; }
public AnylineScanMode(string name, string jsonConfigPath, string configsPath = "Configs/")
{
diff --git a/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml b/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml
deleted file mode 100644
index cbc3923..0000000
--- a/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml.cs b/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml.cs
deleted file mode 100644
index 0f36388..0000000
--- a/MAUI/NFC/MyNFCScanningWithAnylinePage.xaml.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-
-using Anyline.Examples.MAUI.Models;
-using Anyline.Examples.MAUI.Views;
-using Anyline.Examples.MAUI.NFC;
-
-namespace Anyline.Examples.MAUI.NFC;
-
-///
-/// This is your app's page where Anyline will be integrated.
-///
-public partial class MyNFCScanningWithAnylinePage : ContentPage
-{
- private AnylineScanMode _scanMode;
- private MyScanResults _myScanResults;
-
- ///
- /// The constructor initializes a new "NFCScanExampleView" (which is rendered natively in Android),
- /// provides a "myResultAction", which will be called once the scanning process is successfully completed,
- /// and a "myErrorAction", which will be called if an error in the process occurs.
- ///
- /// Object containing the Name of the ScanMode and the JSON config file path (used for initializing the ScanView).
- public MyNFCScanningWithAnylinePage(AnylineScanMode scanMode)
- {
- InitializeComponent();
- _scanMode = scanMode;
-
- Title = scanMode.Name;
-
- Action myResultAction = (r) =>
- {
- // save the results in a variable to display them after this page appears again
- _myScanResults = r;
- };
-
- Action myErrorAction = (errorMessage) =>
- {
- MainThread.BeginInvokeOnMainThread(async () =>
- {
- await DisplayAlert("NFC Error", errorMessage, "OK");
- });
- };
-
- var view = new NFCScanExampleView(scanMode.JSONConfigPath, myResultAction, myErrorAction);
-
- gridContent.Add(view);
- }
-
- // Display the NFC results only after we come back to this page
- // (the NFC Scanning activities/pages)
- protected override void OnAppearing()
- {
- base.OnAppearing();
-
- if (_myScanResults != null)
- {
- ShowNFCResults(_myScanResults, _scanMode);
- }
- }
-
- ///
- /// This method is called inside the Action, used to process the Scan Results.
- ///
- /// The scan results, coming from the native platform.
- /// Object containing the Name of the ScanMode and the JSON config file path (used for re-initializing the ScanView page).
- private void ShowNFCResults(MyScanResults myScanResults, AnylineScanMode scanMode)
- {
- MainThread.InvokeOnMainThreadAsync(new Action(async () =>
- {
- // Opens the Results Page to display the MRZ and NFC data
- Navigation.InsertPageBefore(new NFCResultsPage(myScanResults, scanMode), Navigation.NavigationStack.Last());
- await Navigation.PopAsync();
- }));
- }
-}
\ No newline at end of file
diff --git a/MAUI/NFC/MyScanResults.cs b/MAUI/NFC/MyScanResults.cs
deleted file mode 100644
index c67c6b7..0000000
--- a/MAUI/NFC/MyScanResults.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-namespace Anyline.Examples.MAUI.NFC
-{
- public class MyScanResults
- {
- public MyMRZScanResults MRZResults { get; set; }
- public MyNFCScanResults NFCResults { get; set; }
- }
-
- public class MyMRZScanResults
- {
- public byte[] CroppedImage { get; set; }
- public byte[] FullImage { get; set; }
- public byte[] FaceImage { get; set; }
-
- public string GivenNames { get; set; }
- public string Surname { get; set; }
-
- public string PassportNumber { get; set; }
- public string DateOfBirth { get; set; }
- public string DateOfExpiry { get; set; }
- }
-
- public class MyNFCScanResults
- {
- public byte[] FaceImage { get; set; }
-
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Gender { get; set; }
- public string DocumentNumber { get; set; }
- public string DateOfBirth { get; set; }
- public string DateOfExpiry { get; set; }
- public string DocumentType { get; set; }
- public string IssueAuthority { get; set; }
- public string IssuingCountryCode { get; set; }
- public string Nationality { get; set; }
- public string ValidFrom { get; set; }
- public string ValidUntil { get; set; }
- public string OrganizationalUnit { get; set; }
- public string CertificationAuthority { get; set; }
- public string IssuerCountry { get; set; }
- public string IssuingStateCode { get; set; }
- }
-}
\ No newline at end of file
diff --git a/MAUI/NFC/NFCResultsPage.xaml b/MAUI/NFC/NFCResultsPage.xaml
deleted file mode 100644
index b4b6e5a..0000000
--- a/MAUI/NFC/NFCResultsPage.xaml
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/MAUI/NFC/NFCResultsPage.xaml.cs b/MAUI/NFC/NFCResultsPage.xaml.cs
deleted file mode 100644
index 4d19d78..0000000
--- a/MAUI/NFC/NFCResultsPage.xaml.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-namespace Anyline.Examples.MAUI.NFC;
-
-public partial class NFCResultsPage : ContentPage
-{
- public NFCResultsPage(MyScanResults results, Models.AnylineScanMode scanMode)
- {
- InitializeComponent();
-
- if (results == null)
- return;
-
- ShowResults(results);
-
- btHome.Clicked += async (s, e) => await Navigation.PopToRootAsync();
- btScanAgain.Clicked += (s, e) =>
- {
- MainThread.BeginInvokeOnMainThread(async () =>
- {
- Navigation.InsertPageBefore(new MyNFCScanningWithAnylinePage(scanMode), this);
- await Navigation.PopAsync();
- });
- };
- }
-
- private void ShowResults(MyScanResults results)
- {
- lbMRZGivenNames.Text = results.MRZResults.GivenNames;
- lbMRZSurname.Text = results.MRZResults.Surname;
-
- lbNFCFirstName.Text = results.NFCResults.FirstName;
- lbNFCLastName.Text = results.NFCResults.LastName;
-
- lbMRZPassportNumber.Text = results.MRZResults.PassportNumber;
- lbNFCDocumentNumber.Text = results.NFCResults.DocumentNumber;
-
- //imMrzFaceImage.Source = ImageSource.FromStream(() => new MemoryStream(results.MRZResults.FaceImage));
- imNFCFaceImage.Source = ImageSource.FromStream(() => new MemoryStream(results.NFCResults.FaceImage));
-
- imCutout.Source = ImageSource.FromStream(() => new MemoryStream(results.MRZResults.CroppedImage));
- imFull.Source = ImageSource.FromStream(() => new MemoryStream(results.MRZResults.FullImage));
- }
-}
\ No newline at end of file
diff --git a/MAUI/NFC/NFCScanExampleView.cs b/MAUI/NFC/NFCScanExampleView.cs
deleted file mode 100644
index f5ee146..0000000
--- a/MAUI/NFC/NFCScanExampleView.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-namespace Anyline.Examples.MAUI.NFC;
-
-///
-/// This ContentView is rendered natively in each individual platform.
-/// The scanning results are received via MessagingCenter.
-///
-public class NFCScanExampleView : View
-{
- public string JSONConfigPath = "";
- private MyScanResults myScanResults = new MyScanResults();
-
- public NFCScanExampleView(string jsonConfigPath, Action onResult, Action onError)
- {
- BackgroundColor = Colors.Black;
- JSONConfigPath = jsonConfigPath;
-
- // Listens for the results of the MRZ Scan Result
- MessagingCenter.Subscribe(this, "MRZ_READING_DONE", (s, results) =>
- {
- MessagingCenter.Unsubscribe(this, "MRZ_READING_DONE");
- myScanResults.MRZResults = results;
- });
-
- // Listens for the results of the NFC Scan Result
- MessagingCenter.Subscribe(this, "NFC_SCAN_FINISHED_SUCCESS", (s, results) =>
- {
- MessagingCenter.Unsubscribe(this, "NFC_SCAN_FINISHED_SUCCESS");
- myScanResults.NFCResults = results;
-
- onResult?.Invoke(myScanResults);
- });
-
- // Listens for errors on the NFC Scanning Process
- MessagingCenter.Subscribe(this, "NFC_SCAN_FINISHED_ERROR", (s, message) =>
- {
- MessagingCenter.Unsubscribe(this, "NFC_SCAN_FINISHED_ERROR");
- onError?.Invoke(message);
- });
- }
-}
diff --git a/MAUI/Platforms/Android/AndroidManifest.xml b/MAUI/Platforms/Android/AndroidManifest.xml
index 28577e4..dc422f7 100644
--- a/MAUI/Platforms/Android/AndroidManifest.xml
+++ b/MAUI/Platforms/Android/AndroidManifest.xml
@@ -4,10 +4,8 @@
-
-
-
+
\ No newline at end of file
diff --git a/MAUI/Platforms/Android/NFC/NFCScanActivity.cs b/MAUI/Platforms/Android/NFC/NFCScanActivity.cs
deleted file mode 100644
index 9bd9da9..0000000
--- a/MAUI/Platforms/Android/NFC/NFCScanActivity.cs
+++ /dev/null
@@ -1,197 +0,0 @@
-using System;
-using Anyline.Examples.MAUI.NFC;
-
-using Android.App;
-using android_app=Android.App;
-using Android.Content;
-using Android.Content.Res;
-using Android.Graphics;
-using Android.OS;
-using Android.Runtime;
-using Android.Util;
-using android_widgets=Android.Widget;
-
-using Android.Nfc;
-using Android.Nfc.Tech;
-using IO.Anyline.Nfc;
-using IO.Anyline.Nfc.NFC;
-
-namespace Anyline.Examples.MAUI.Platforms.Android.NFC
-{
- [Activity(Label = "NFCScanActivity")]
- public class NFCScanActivity : Activity, INfcDetectionHandler
- {
- protected NfcAdapter mNfcAdapter;
-
- private string passportNumber;
- private string dateOfExpiry;
- private string dateOfBirth;
-
- android_widgets.ProgressBar nfcReadProgressBar;
-
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
-
- Title = "Scan NFC";
-
- // You can customize this Activity so it best fits your App's visual identity and requirements
- SetContentView(Resource.Layout.ActivityNFC);
- nfcReadProgressBar = (android_widgets.ProgressBar)FindViewById(Resource.Id.readProgressBar);
-
- // Obtains the system's NFC Service
- NfcManager NfcManager = (NfcManager)android_app.Application.Context.GetSystemService(NfcService);
- mNfcAdapter = NfcManager.DefaultAdapter;
-
- // Retrieves the passport information from the previous activity
- if (Intent != null)
- {
- try
- {
- passportNumber = Intent.GetStringExtra("pn");
- dateOfBirth = Intent.GetStringExtra("db");
- dateOfExpiry = Intent.GetStringExtra("de");
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- }
- }
-
- ///
- /// OnResume, we start listening for the NFC Tag.
- ///
- protected override void OnResume()
- {
- base.OnResume();
-
- try
- {
- if (mNfcAdapter != null)
- {
- var intent = new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop);
-
- mNfcAdapter.EnableForegroundDispatch(
- this,
- PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Mutable),
- new[] { new IntentFilter(NfcAdapter.ActionTechDiscovered) },
- new string[][] {
- new string[] {
- "android.nfc.tech.IsoDep",
- },
- }
- );
- }
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("onResume error: " + e.Message);
- }
- }
-
- ///
- /// OnPause, we stop listening for the NFC Tag.
- ///
- protected override void OnPause()
- {
- base.OnPause();
- if (mNfcAdapter != null)
- {
- mNfcAdapter.DisableForegroundDispatch(this);
- }
- }
-
- ///
- /// OnNewIntent we check if the NFC Tag was recognized, and start the detection.
- ///
- ///
- protected override void OnNewIntent(Intent intent)
- {
- base.OnNewIntent(intent);
-
- Tag tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
- TagProvider.Tag = IsoDep.Get(tag);
-
- if (NfcAdapter.ActionTechDiscovered == intent.Action)
- {
- if (tag.GetTechList().ToList().Contains("android.nfc.tech.IsoDep"))
- {
- try
- {
- // Begins to read the NFC chip
- NfcDetector nfcDetector = new NfcDetector(ApplicationContext, this);
- nfcDetector.StartNfcDetection(passportNumber, dateOfBirth, dateOfExpiry);
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- }
- }
- }
-
- /* As the NFC reading may take a few seconds, we show a progress bar to the user, increasing it's value after each DataGroup read */
- public void OnDg1Success(DataGroup1 dataGroup1)
- {
- MainThread.BeginInvokeOnMainThread(() => nfcReadProgressBar.SetProgress(nfcReadProgressBar.Progress + 33, true));
- }
-
- public void OnSODSuccess(SOD sod)
- {
- MainThread.BeginInvokeOnMainThread(() => nfcReadProgressBar.SetProgress(nfcReadProgressBar.Progress + 33, true));
- }
-
- public void OnDg2Success(Bitmap faceImage)
- {
- MainThread.BeginInvokeOnMainThread(() => nfcReadProgressBar.SetProgress(nfcReadProgressBar.Progress + 33, true));
- }
-
- ///
- /// Once the NFC reading is done, we send the results back to the Xamarin.Forms layer
- ///
- /// The NFC results
- public void OnNfcSuccess(NFCResult result)
- {
- // Once we have the results, we don't need to react to the NFC Tag anymore.
- mNfcAdapter.DisableForegroundDispatch(this);
-
- MainThread.BeginInvokeOnMainThread(() => nfcReadProgressBar.SetProgress(100, true));
-
- MyNFCScanResults myNFCScanResults = new MyNFCScanResults
- {
- FirstName = result.DataGroup1.FirstName,
- LastName = result.DataGroup1.LastName,
- Gender = result.DataGroup1.Gender,
- DocumentNumber = result.DataGroup1.DocumentNumber,
- DateOfBirth = result.DataGroup1.DateOfBirth,
- DateOfExpiry = result.DataGroup1.DateOfExpiry,
- DocumentType = result.DataGroup1.DocumentType,
- IssuingStateCode = result.DataGroup1.IssuingStateCode,
- Nationality = result.DataGroup1.Nationality,
- FaceImage = ConvertBitmapToByteArray(result.DataGroup2.FaceImage)
- };
-
- // Sends the parsed results to the Message Listener (in this example, the NFCScanExamplePage)
- MessagingCenter.Send(App.Current, "NFC_SCAN_FINISHED_SUCCESS", myNFCScanResults);
-
- // Finishes this native NFC scanning activity
- Finish();
- }
-
- public void OnNfcFailure(string e)
- {
- MessagingCenter.Send(App.Current, "NFC_SCAN_FINISHED_ERROR", e);
-
- // Finishes this native NFC scanning activity
- Finish();
- }
-
- public byte[] ConvertBitmapToByteArray(Bitmap bitmap)
- {
- MemoryStream stream = new MemoryStream();
- bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
- return stream.ToArray();
- }
- }
-}
\ No newline at end of file
diff --git a/MAUI/Platforms/Android/NFC/NFCScanningViewRenderer.cs b/MAUI/Platforms/Android/NFC/NFCScanningViewRenderer.cs
deleted file mode 100644
index c5a1bad..0000000
--- a/MAUI/Platforms/Android/NFC/NFCScanningViewRenderer.cs
+++ /dev/null
@@ -1,191 +0,0 @@
-using System;
-using System.IO;
-using Android.App;
-using Android.Content;
-using Android.Graphics;
-using Android.Util;
-using Android.Widget;
-using Anyline.Examples.MAUI.NFC;
-using Anyline.Examples.MAUI.Platforms.Android.NFC;
-using IO.Anyline2.Camera;
-using IO.Anyline.Plugin.Result;
-using IO.Anyline2;
-using IO.Anyline2.View;
-using Microsoft.Maui.Controls.Handlers.Compatibility;
-using Microsoft.Maui.Controls.Platform;
-
-namespace Anyline.Examples.MAUI.Platforms.Android.NFC
-{
- public class NFCScanningViewRenderer : ViewRenderer, IEvent
- {
- private bool _initialized;
- private IO.Anyline2.View.ScanView _scanView;
- private Context _context;
-
- public NFCScanningViewRenderer(Context context) : base(context)
- {
- _context = context;
- }
-
- protected override void OnElementChanged(ElementChangedEventArgs e)
- {
- base.OnElementChanged(e);
- if (e.OldElement != null || Element == null)
- {
- return;
- }
- }
-
- protected override void OnAttachedToWindow()
- {
- base.OnAttachedToWindow();
- InitializeAnyline();
- }
-
-
- private void InitializeAnyline()
- {
- if (_initialized)
- return;
-
- try
- {
- _scanView = new IO.Anyline2.View.ScanView(_context);
-
- // Obtain the JSON config file path from the "AnylineScanningView", defined in the MAUI level.
- string jsonConfigFilePath = (Element as NFCScanExampleView).JSONConfigPath.Replace(".json", "") + ".json";
-
- // This is the main intialization method that will create our use case depending on the JSON configuration.
- _scanView.Init(jsonConfigFilePath);
-
- _scanView.ScanViewPlugin.ResultReceived = this;
-
- // Handle camera open events
- _scanView.CameraView.CameraOpened += _scanView_CameraOpened;
-
- // Handle camera error events
- _scanView.CameraView.CameraError += _scanView_CameraError;
-
- AddView(_scanView);
- }
- catch (Exception e)
- {
- // show error
- Toast.MakeText(_context, e.ToString(), ToastLength.Long).Show();
- Log.Debug("NFCScanningViewRenderer - Android", e.ToString());
- }
- }
-
- private void _scanView_CameraError(object sender, CameraErrorEventArgs e)
- {
- Log.Debug("NFCScanningViewRenderer - Android", e.ToString());
- }
-
- private void _scanView_CameraOpened(object sender, CameraOpenedEventArgs e)
- {
- if (_scanView != null)
- _scanView.Start();
- }
-
-
- ///
- /// This method is called when a scan result is found.
- /// Since the native Java type is generic, we translated the type of the parameter to ScanResult due to .NET Android generic binding limitations.
- ///
- /// The scan result
- public void EventReceived(Java.Lang.Object data)
- {
- if (data == null) return;
-
- var scanResult = data as IO.Anyline2.ScanResult;
- PluginResult pluginResult = scanResult.PluginResult;
- var mrzResult = pluginResult.MrzResult;
-
- // Sends the MRZ results back to the MAUI layer
- MyMRZScanResults myMRZScanResults = new MyMRZScanResults
- {
- GivenNames = mrzResult.GivenNames,
- Surname = mrzResult.Surname,
- CroppedImage = ConvertAnylineImageToByteArray(scanResult.CutoutImage),
- FullImage = ConvertAnylineImageToByteArray(scanResult.Image),
- //FaceImage = ConvertBitmapToByteArray(scanResult.FaceImage), //not available yet
- PassportNumber = mrzResult.DocumentNumber.Trim(),
- DateOfBirth = mrzResult.DateOfBirth,
- DateOfExpiry = mrzResult.DateOfExpiry
- };
- MessagingCenter.Send(App.Current, "MRZ_READING_DONE", myMRZScanResults);
-
- StartReadingNFCChip(mrzResult.DocumentNumber, mrzResult.DateOfBirth, mrzResult.DateOfExpiry);
- }
-
- private void StartReadingNFCChip(string documentNumber, string dateOfBirth, string dateOfExpiry)
- {
- // Gets the data necessary for the NFC reading
- string passportNumber = documentNumber.Trim();
- // The passport number passed to the NFC chip must have a trailing < if there is one in the MRZ string.
- while (passportNumber.Length < 9)
- {
- passportNumber += "<";
- }
-
- // Open the Activity responsible for listening to the NFC calls and reading the chip.
- // We use data from the MRZ to authenticate with the chip.
-
- var activity = this.Context as Activity;
- var nfcActivity = new Intent(activity, typeof(NFCScanActivity));
- nfcActivity.PutExtra("pn", passportNumber);
- nfcActivity.PutExtra("db", dateOfBirth);
- nfcActivity.PutExtra("de", dateOfExpiry);
- activity.StartActivityForResult(nfcActivity, 0);
- }
-
- private byte[] ConvertAnylineImageToByteArray(IO.Anyline2.Image.AnylineImage anylineImage)
- {
- if (anylineImage == null) return null;
-
- var bitmap = anylineImage.Bitmap;
-
- MemoryStream stream = new MemoryStream();
- bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
- return stream.ToArray();
- }
-
- private byte[] ConvertBitmapToByteArray(Bitmap bitmap)
- {
- if (bitmap == null) return null;
-
- MemoryStream stream = new MemoryStream();
- bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
- return stream.ToArray();
- }
-
- #region Teardown
- protected override void OnDetachedFromWindow()
- {
- base.OnDetachedFromWindow();
- DisposeAnyline();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- DisposeAnyline();
- }
-
- private void DisposeAnyline()
- {
- if (_scanView != null)
- {
- _scanView.Stop();
- _scanView.CameraView.CameraOpened -= _scanView_CameraOpened;
- _scanView.CameraView.CameraError -= _scanView_CameraError;
- _scanView.CameraView.ReleaseCameraInBackground();
- _scanView.Dispose();
- _scanView = null;
- }
- _initialized = false;
- RemoveAllViews();
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/MAUI/Platforms/Android/Resources/layout/ActivityNFC.xml b/MAUI/Platforms/Android/Resources/layout/ActivityNFC.xml
deleted file mode 100644
index 1fd6f72..0000000
--- a/MAUI/Platforms/Android/Resources/layout/ActivityNFC.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MAUI/Platforms/iOS/Entitlements.plist b/MAUI/Platforms/iOS/Entitlements.plist
index b720bea..7191ed6 100644
--- a/MAUI/Platforms/iOS/Entitlements.plist
+++ b/MAUI/Platforms/iOS/Entitlements.plist
@@ -2,10 +2,5 @@
- com.apple.developer.nfc.readersession.formats
-
- NDEF
- TAG
-
diff --git a/MAUI/Platforms/iOS/Info.plist b/MAUI/Platforms/iOS/Info.plist
index 53a5c48..7427663 100644
--- a/MAUI/Platforms/iOS/Info.plist
+++ b/MAUI/Platforms/iOS/Info.plist
@@ -30,12 +30,6 @@
Assets.xcassets/appicon.appiconset
NSCameraUsageDescription
The camera permission is required for the scanning capability.
- com.apple.developer.nfc.readersession.iso7816.select-identifiers
-
- A0000002471001
-
- NFCReaderUsageDescription
- Please allow NFC access to read passports
CFBundleIdentifier
com.anyline.maui.examples
MinimumOSVersion
diff --git a/MAUI/Platforms/iOS/NFC/NFCScanningViewRenderer.cs b/MAUI/Platforms/iOS/NFC/NFCScanningViewRenderer.cs
deleted file mode 100644
index 05d6be7..0000000
--- a/MAUI/Platforms/iOS/NFC/NFCScanningViewRenderer.cs
+++ /dev/null
@@ -1,191 +0,0 @@
-using Anyline.Examples.MAUI.NFC;
-using Microsoft.Maui.Controls.Handlers.Compatibility;
-using Foundation;
-using UIKit;
-using Anyline.SDK.NET.iOS;
-
-namespace Anyline.Examples.MAUI.Platforms.iOS.NFC
-{
- public class NFCScanningViewRenderer : ViewRenderer, IALScanPluginDelegate, IALNFCDetectorDelegate
- {
- private ALScanView _scanView;
-
- ALNFCDetector _nfcDetector;
-
- public override void WillMoveToWindow(UIWindow window)
- {
- base.WillMoveToWindow(window);
- if (window != null)
- {
- InitializeAnylineScanView();
- NSError error = null;
- _nfcDetector = new ALNFCDetector(this, out error);
- }
- else
- {
- DisposeAnyline();
- }
- }
-
- private void InitializeAnylineScanView()
- {
- try
- {
- NSError error = null;
-
- string configurationFile = (Element as NFCScanExampleView).JSONConfigPath.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.
- _scanView = ALScanViewFactory.WithConfigFilePath(configPath, this, out error);
-
- if (error != null)
- {
- throw new Exception(error.LocalizedDescription);
- }
-
- Add(_scanView);
-
- _scanView.StartCamera();
- }
- catch (Exception e)
- {
- ShowAlert("Init Error", e.Message);
- }
- }
-
- ///
- /// This method is called after the _scanView is added.
- ///
- /// The _scanView itself
- public override void SubviewAdded(UIView uiview)
- {
- base.SubviewAdded(uiview);
-
- // To allow rotation, pin the edge of the scan view to the parent view:
- _scanView.TranslatesAutoresizingMaskIntoConstraints = false;
-
- _scanView.LeadingAnchor.ConstraintEqualTo(Superview.LeadingAnchor).Active = true;
- _scanView.TrailingAnchor.ConstraintEqualTo(Superview.TrailingAnchor).Active = true;
- _scanView.TopAnchor.ConstraintEqualTo(Superview.SafeAreaLayoutGuide.TopAnchor).Active = true;
- _scanView.BottomAnchor.ConstraintEqualTo(Superview.BottomAnchor).Active = true;
-
- // Start scanning!
- BeginInvokeOnMainThread(() => StartMRZScanner());
- }
-
- private void StartMRZScanner()
- {
- NSError error = null;
- var success = _scanView.ViewPlugin.StartWithError(out error);
- if (!success)
- {
- if (error != null)
- ShowAlert("Start Scanning Error", error.DebugDescription);
- else
- ShowAlert("Start Scanning Error", "error is null");
- }
- }
-
- private void ShowAlert(string title, string text)
- {
- new UIAlertView(title, text, (IUIAlertViewDelegate)null, "OK", null).Show();
- }
-
- [Export("scanPlugin:resultReceived:")]
- public void ResultReceived(ALScanPlugin scanPlugin, ALScanResult scanResult)
- {
- ALMrzResult mrzResult = scanResult.PluginResult.MrzResult;
-
- // Sends the MRZ results back to the Xamarin Forms application
- MyMRZScanResults myMRZScanResults = new MyMRZScanResults
- {
- GivenNames = mrzResult.GivenNames,
- Surname = mrzResult.Surname,
- CroppedImage = scanResult.CroppedImage.AsJPEG().ToArray(),
- FullImage = scanResult.FullSizeImage.AsJPEG().ToArray(),
- FaceImage = scanResult.FaceImage.AsJPEG().ToArray(),
- PassportNumber = mrzResult.DocumentNumber.Trim(),
- DateOfBirth = mrzResult.DateOfBirth,
- DateOfExpiry = mrzResult.DateOfExpiry
- };
- MessagingCenter.Send(App.Current, "MRZ_READING_DONE", myMRZScanResults);
-
- // Gets the data necessary for the NFC reading
- string passportNumber = mrzResult.DocumentNumber.Trim();
- NSDate dateOfBirth = ConvertToNSDate(mrzResult.DateOfBirthObject);
- NSDate dateOfExpiry = ConvertToNSDate(mrzResult.DateOfExpiryObject);
-
- // The passport number passed to the NFC chip must have a trailing < if there is one in the MRZ string.
- while (passportNumber.Length < 9)
- {
- passportNumber += "<";
- }
-
- // This is where we start reading the NFC chip of the passport.
- // We use data from the MRZ to authenticate with the chip.
- BeginInvokeOnMainThread(() =>
- {
- _nfcDetector.StartNfcDetectionWithPassportNumber(passportNumber, dateOfBirth, dateOfExpiry);
- });
- }
-
- ///
- /// Converts date strings from this: "Sun Apr 12 00:00:00 UTC 1977" to this: "04/12/1977"
- ///
- /// Date string to be converted
- /// NSDate of the informed date
- private NSDate ConvertToNSDate(string dateString)
- {
- NSDateFormatter dateFormatter = new NSDateFormatter();
- dateFormatter.TimeZone = NSTimeZone.FromAbbreviation("GMT+0:00");
- dateFormatter.DateFormat = @"E MMM d HH:mm:ss zzz yyyy";
- dateFormatter.Locale = NSLocale.FromLocaleIdentifier("en_US_POSIX");
- NSDate nsDate = dateFormatter.Parse(dateString);
- return nsDate;
- }
-
- #region NFC Result
- public void NfcSucceededWithResult(ALNFCResult nfcResult)
- {
- MyNFCScanResults myNFCScanResults = new MyNFCScanResults
- {
- FirstName = nfcResult.DataGroup1.FirstName,
- LastName = nfcResult.DataGroup1.LastName, // The Last Name is returned without the spaces between the names (eg. SURNAME1SURNAME2)
- Gender = nfcResult.DataGroup1.Gender,
- DocumentNumber = nfcResult.DataGroup1.DocumentNumber,
- DateOfBirth = nfcResult.DataGroup1.DateOfBirth.ToString(),
- DateOfExpiry = nfcResult.DataGroup1.DateOfExpiry.ToString(),
- DocumentType = nfcResult.DataGroup1.DocumentType,
- IssuingStateCode = nfcResult.DataGroup1.IssuingStateCode,
- Nationality = nfcResult.DataGroup1.Nationality,
- FaceImage = nfcResult.DataGroup2.FaceImage.AsJPEG().ToArray()
- };
-
- // Sends the parsed results to the Message Listener (in this example, the NFCScanExamplePage)
- MessagingCenter.Send(App.Current, "NFC_SCAN_FINISHED_SUCCESS", myNFCScanResults);
- }
-
- public void NfcFailedWithError(NSError error)
- {
- MessagingCenter.Send(App.Current, "NFC_SCAN_FINISHED_ERROR", error.ToString());
- StartMRZScanner();
- }
- #endregion
-
- #region teardown
- protected void DisposeAnyline()
- {
- if (_scanView != null && _scanView.ViewPlugin != null)
- {
- _scanView.ViewPlugin.Stop();
- }
-
- _scanView?.Dispose();
- _scanView?.RemoveFromSuperview();
- _scanView = null;
- }
- #endregion
- }
-}
\ No newline at end of file