Skip to content

Commit

Permalink
Update to latest native SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Miquel-Martinez committed Jul 26, 2024
1 parent 258e959 commit b753c96
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 55 deletions.
6 changes: 3 additions & 3 deletions ExampleAppMAUI/ExampleAppMAUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">12.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">13.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">26.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
Expand Down Expand Up @@ -75,7 +75,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="iProov.NET.MAUI" Version="1.1.0" />
<PackageReference Include="iProov.NET.MAUI" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\APIClient\APIClient.csproj" />
Expand Down
8 changes: 4 additions & 4 deletions ExampleAppMAUI/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using iProov.APIClient;
using iProov.NET.MAUI;

Expand Down Expand Up @@ -47,7 +47,7 @@ private async void OnLaunchIProov(object sender, EventArgs e)
try
{
var token = await apiClient.GetToken(assuranceType, claimType, userId);
launchIProov(token, userId);
launchIProov(token);
}
catch (Exception exception)
{
Expand All @@ -60,7 +60,7 @@ private async void OnLaunchIProov(object sender, EventArgs e)
}
}

private void launchIProov(string token, string userId)
private void launchIProov(string token)
{
DisableControlElements();
ClaimFrame.Source = null;
Expand All @@ -71,7 +71,7 @@ private void launchIProov(string token, string userId)
// CustomizeOptions(options)

Console.WriteLine("Launching iPROOV --- ");
wrapper.LaunchIProov(token, userId, Credentials.BASE_URL, this, options);
wrapper.LaunchIProov(token, Credentials.BASE_URL, this, options);
}

private void CustomizeOptions(IProovOptions options)
Expand Down
Binary file modified ExampleAppMAUI/Resources/AppIcon/icon_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ExampleAppMAUI/Resources/Images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ExampleAppMAUI/Resources/Splash/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
178 changes: 141 additions & 37 deletions Nuget Packages/iProov.NET.Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,36 @@ The iProov.NET.Android NuGet enables you to integrate iProov's SDK into your .NE

This NuGet wraps iProov's existing native [Android](https://github.com/iProov/android) SDK behind a .NET interface for use from within your .NET app.

For a more extensive documentation on iProov's .NET packages check the public GitHub repository [here](https://github.com/iProov/dotnet-maui).

## Use Flows and Coroutines

Since version `10.0.0` of the [Android](https://github.com/iProov/android) SDK the use of Flows is necessary to collect information from a claim.

When using iProov.NET.Android integrators need to use the .NET libraries for Flows and Coroutines and create the necessary classes to handle the values returned by the SDK. This is all explained in the [How to use it](#how-to-use-it) section and the code for the necessary classes can be found [here](need-to-do).

As an alternative solution, integrators can use the iProov.NET.MAUI package instead ([here](https://github.com/iProov/dotnet-maui)), which already wraps the `iProov.NET.Android` package into a callback based API.

## Requirements

- NET 8 (net8-android)
- Android API Level 21 (Android 5 Lollipop) and above
- Android API Level 26 (Android 8) and above

## How to use it

1. Using the NuGet Package Manager, add the [iProov.NET.Android](https://www.nuget.org/packages/iProov.NET.Android/) package to your project. For further instructions on how to install and manage packages, [see here](https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio).

2. Import the package into your project with `using iProov.NET.Android;`
> The approach presented next assumes the following classes are used:
> * [IStateListener](#istatelistener) interface to to be implemented to receive `iProov.State` updates.
> * [FlowCollector](#flowcollector) to collect the states from a `Session` and notify those changes to the `IStateListener`
> * [FlowContinuation](#flowcontinuation) necessary to collect values from a flow.
3. Create an instance of IProovCallbackLauncher
1. Using the NuGet Package Manager, add the [iProov.NET.Android](https://www.nuget.org/packages/iProov.NET.Android/) package to your project.

```csharp
IProovCallbackLauncher iProovLauncher = new IProovCallbackLauncher();
```
2. Import the package into your project with `using iProov.NET.Android;`

4. Create a private class which implements `IProovCallbackLauncher.IListener` to handle the callbacks from the Android SDK:
3. Create a class which implements `IStateListener` to handle the callbacks from the Android SDK:

```csharp
private IProovListener listener = new IProovListener();

private class IProovListener : Java.Lang.Object, IProov.IListener
```csharp
public class IProovListener : IStateListener
{

public void OnConnected()
Expand All @@ -47,7 +54,7 @@ This NuGet wraps iProov's existing native [Android](https://github.com/iProov/an
{
// Either the user canceled iProov by pressing the Close button at the top right or
// the Home button (canceler == USER)
// Or the app canceled using Session.cancel() (canceler == APP).
// The session was canceled by the integrator using Session.cancel() (canceler == INTEGRATION).
// You should use this to determine the next step in your flow.
}
Expand Down Expand Up @@ -85,38 +92,135 @@ This NuGet wraps iProov's existing native [Android](https://github.com/iProov/an

```

> Alternatively you could just implement `IProov.IListener` on your `Activity` class.
> Alternatively you could just implement `IStateListener` on your `Activity` class.

5. You must register the iProov listener when your Activity is created:
4. Create an instance of `FlowCollector` passing your `IStateListener` in the constructor.

```csharp

IProovCallbackLauncher iProovLauncher = new IProovCallbackLauncher();
IProovListener listener = new IProovListener();

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
iProovLauncher.Listener = listener;
// ...continue your activity setup ...
private void launchIProov() {
...
IProovListener listener = new IProovListener();
FlowCollector flowCollector = new FlowCollector(listener);
...
}
```

...and unregister it when destroyed:
5. Once you have obtained a token (either via the [.NET API Client](https://github.com/iProov/dotnet-maui/tree/master/APIClient) or other means), you can now launch iProov. To do so, first you need to create a `Session` and set up the collection of `State` values for it (use `FlowContinuation` here), after that you can `start` the session:

```csharp
protected override void OnDestroy()
{
iProovLauncher.Listener = null;
base.OnDestroy();
}
```
private void launchIProov() {
...
IProovListener listener = new IProovListener();
FlowCollector flowCollector = new FlowCollector(listener);
FlowContinuation continuation = new FlowContinuation();

6. Once you have obtained a token (either via the [.NET API Client](https://github.com/iProov/dotnet-maui/tree/master/APIClient) or other means), you can now launch iProov by calling:
IProov.Options options = new IProov.Options();

```csharp
iProovLauncher.Launch(this, "wss://eu.rp.secure.iproov.me/ws", token, new IProov.Options()); // Substitute the streaming URL as appropriate
IProov.ISession session = IProov.Instance.CreateSession(this, "wss://eu.rp.secure.iproov.me/ws", token, options);
session.State.Collect(flowCollector, continuation);
session.Start();
}
```

👉 You should now familiarise yourself with the [iProov Android SDK documentation](https://github.com/iProov/android) which provides comprehensive details about the available customization options and other important details regarding the Android SDK usage.

### Canceling the session

Under normal circumstances, a session will be canceled by the user (Canceler.USER) by pressing the back button or the close button. However, there may be situations where an integrator may need to cancel an ongoing session. For those situations, integrators can invoke the `Cancel()` method from the `ISession` created to perform a scan.

```csharp
IProov.ISession session = IProov.Instance.CreateSession(context, wss_url, token, options);

session.Cancel();
```

## Additional code

### IStateListener
```csharp
namespace <YOUR_NAMESPACE>;

using iProov.NET.Android;

public interface IStateListener
{
void OnCanceled(IProov.Canceler canceler);
void OnConnected();
void OnConnecting();
void OnError(IProovException exception);
void OnFailure(IProov.FailureResult failure);
void OnProcessing(double progress, string? message);
void OnSuccess(IProov.SuccessResult successResult);
}
```

### FlowCollector
```csharp
namespace <YOUR_NAMESPACE>;

using iProov.NET.Android;
using Xamarin.KotlinX.Coroutines.Flow;
using Kotlin.Coroutines;

public class FlowCollector : Java.Lang.Object, IFlowCollector
{
private IStateListener listener;
public FlowCollector(IStateListener callbackListener) {
listener = callbackListener;
}

public Java.Lang.Object? Emit(Java.Lang.Object? value, IContinuation p1)
{
if (value != null && value is IProov.State state) {
notifyListener(state);
p1.ResumeWith(value);
}

return value;
}

private void notifyListener(IProov.State state) {
switch (state)
{
case IProov.State.Connected:
listener.OnConnected();
break;
case IProov.State.Connecting:
listener.OnConnecting();
break;
case IProov.State.Processing:
if (state is IProov.State.Processing processing)
listener.OnProcessing(processing.Progress, processing.Message);
break;
case IProov.State.Canceled:
if (state is IProov.State.Canceled canceled)
listener.OnCanceled(canceled.Canceler);
break;
case IProov.State.Error:
if (state is IProov.State.Error error)
listener.OnError(error.Exception);
break;
case IProov.State.Failure:
if (state is IProov.State.Failure failure)
listener.OnFailure(failure.FailureResult);
break;
case IProov.State.Success:
if (state is IProov.State.Success success)
listener.OnSuccess(success.SuccessResult);
break;
}
}
}
```

### FlowContinuation
```csharp
namespace <YOUR_NAMESPACE>;

using Kotlin.Coroutines;
public class FlowContinuation : Java.Lang.Object, IContinuation
{
public ICoroutineContext Context => EmptyCoroutineContext.Instance;
public void ResumeWith(Java.Lang.Object result){}
}
```
Binary file not shown.
Binary file not shown.
30 changes: 25 additions & 5 deletions Nuget Packages/iProov.NET.iOS/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# iProov.NET.iOS Nuget
# iProov.NET.iOS NuGet

## Introduction

The iProov.NET.iOS NuGet enables you to integrate iProov's SDK into your .NET iOS projects.

This NuGet wraps iProov's existing native [iOS](https://github.com/iProov/ios) SDK behind a .NET interface for use from within your .NET app.

For a more extensive documentation on iProov's .NET packages check the public GitHub repository [here](https://github.com/iProov/dotnet-maui).

## Requirements

- NET 8 (net8-ios)
- iOS 12 and above
- iOS 13 and above


## How to use it

1. Using the NuGet Package Manager, add the [iProov.NET.iOS](https://www.nuget.org/packages/iProov.NET.iOS/) package to your project. For further instructions on how to do this, [see here](https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio).
1. Using the NuGet Package Manager, add the [iProov.NET.iOS](https://www.nuget.org/packages/iProov.NET.iOS/) package to your project.

2. Add a "Privacy - Camera Usage Description" entry to your Info.plist file with the reason why your app requires camera access (e.g. "To iProov you in order to verify your identity.")

Expand All @@ -37,7 +39,7 @@ This NuGet wraps iProov's existing native [iOS](https://github.com/iProov/ios) S
processing: (progress, message) =>
{
// The SDK will update your app with the progress of streaming to the server and authenticating
// the user. This will be called multiple time as the progress updates.
// the user. This will be called multiple times as the progress updates.
},
success: (result) =>
{
Expand All @@ -50,7 +52,7 @@ This NuGet wraps iProov's existing native [iOS](https://github.com/iProov/ios) S
{
// Either the user canceled iProov by pressing the Close button at the top left or sending
// the app to the background. (canceler == USER)
// Or the app canceled using Session.cancel() (canceler == APP).
// Or the app canceled using Session.cancel() (canceler == INTEGRATION).
// You should use this to determine the next step in your flow.
},
failure: (result) =>
Expand All @@ -71,5 +73,23 @@ This NuGet wraps iProov's existing native [iOS](https://github.com/iProov/ios) S
);
```
> Note that the launch method requires the url to be passed as a **NSURL**
### Canceling the session

Under normal circumstances, the user will be in control of the completion of the iProov scan, i.e. they will either complete the scan, or use the close button to cancel. In some cases, you (the integrator) may wish to cancel the iProov scan programmatically, for example in response to a timeout or change of conditions in your app.

To cancel the session, you first need to hold a reference to the `IPSession` object (returned from `IProov.LaunchWithStreamingURL`) and you can then call `Cancel()` on it.

```csharp
IPSession session = IProov.LaunchWithStreamingURL(...)

// Example - cancel the session after 10 sec
System.Timers.Timer timer = new System.Timers.Timer(10000);
timer.Elapsed += (sender, e) =>
{
session.Cancel(); // Will return true if the session was successfully canceled
};
timer.Enabled = true;
```

👉 You should now familiarise yourself with the [iProov iOS SDK documentation](https://github.com/iProov/ios) which provides comprehensive details about the available customization options and other important details regarding the iOS SDK usage.
Binary file not shown.
Loading

0 comments on commit b753c96

Please sign in to comment.