faceping.aidocs

Get started with .NET MAUI

Build a small app that enrols your face and verifies it offline, on your own phone.

What you'll build

A face check that works in airplane mode

An app that enrols your face, verifies it live with a head-turn liveness check, and still matches with no network.

About 10 minutesAndroid or iPhoneFree sandbox key
0 of 7 steps doneAbout 10 minutes
FaceCheck
Look at the cameraTap Enrol my face to start.

1

Get a sandbox key#

Sign up at app.faceping.ai/signup with your email, then open Developers → Sandbox keys → Create sandbox key. It starts with fp_test_. It also works on the API for your practice list, so keep test apps within your team, and revoke the key under Developers if it leaks.

The sandbox is free and instant: up to 25 faces per device, each deleted 24 hours after it was enrolled. No card, no approval.

2

Create the project#

You need the .NET 10 SDK with the MAUI workload, and a phone with a cable: an Android phone (Android 7 or later, 64-bit) or an iPhone (iOS 15.1 or later).

dotnet new maui -n FaceCheck
cd FaceCheck
First .NET MAUI app on this machine?

The 10 minutes assume your machine already builds MAUI apps. If it doesn't, set it up first (the workload and Android tools take a while to download):

  • .NET MAUI: dotnet workload install maui (on macOS it may need sudo, and it takes a few minutes).
  • Android: the Android SDK and a JDK. Install them with Android Studio, or let .NET fetch them with dotnet build -t:InstallAndroidDependencies (Microsoft's installation guide has the full command and where to point it). Turn on USB debugging on the phone.
  • iPhone: a Mac with Xcode 26 or later, signed in with your Apple ID (Xcode → Settings → Apple Accounts).

Then make two changes in FaceCheck.csproj. FacePing runs on Android and iOS phones, so keep just those two targets (Mac Catalyst and Windows aren't supported), and raise the minimums to Android 7 (API 24) and iOS 15.1. The template's Android minimum is lower, and the build stops with a message until you change it:

FaceCheck.csproj
<!-- Replace the TargetFrameworks lines with: -->
<TargetFrameworks>net10.0-android;net10.0-ios</TargetFrameworks>

<!-- Change the minimums: Android from 21.0 to 24.0, iOS from 15.0 to 15.1: -->
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.1</SupportedOSPlatformVersion>

<!-- And delete the maccatalyst and windows SupportedOSPlatformVersion lines (and TargetPlatformMinVersion),
     plus the template's long comment about Mac Catalyst. WindowsPackageType and its Microsoft Store comment
     can go too (harmless if they stay). -->

If a Mac Catalyst or Windows target stays in, a build of the whole project stops at once with FACEPING002 and says to remove it. (Building one platform with -f, as below, only checks that platform.)

While you're there, change <ApplicationId> from com.companyname.facecheck to your own reverse-DNS id, for example com.yourcompany.facecheck. iOS signs the app with it.

3

Add FacePing#

One package. It brings the face models, liveness checks and a camera view with it.

dotnet add package FacePing.Sdk.Maui --prerelease

FacePing for MAUI is in preview: --prerelease gets the latest preview from NuGet.

The first restore downloads about 170 MB, mostly Microsoft's ONNX Runtime (the engine the face models run on). After that it comes from your NuGet cache. Expect an Android app of about 60 MB and an iPhone app of about 80 MB; see the size note under Run it on your phone for a smaller Android app.

4

Allow the camera#

Both platforms ask the user before the camera turns on. Add the line for each platform you'll run on.

<!-- Platforms/Android/AndroidManifest.xml, inside <manifest> -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Platforms/iOS/Info.plist, inside <dict> -->
<key>NSCameraUsageDescription</key>
<string>FaceCheck uses the camera to verify your face.</string>

On Android, keep face data out of backups. FacePing encrypts it with a key kept in the Android Keystore, which backups don't include, so a backed-up copy could never be read on another phone (and face data shouldn't leave the device anyway). Turn backup off, and add rules for Android 12 and later, which also copy data when someone moves to a new phone:

<!-- Platforms/Android/AndroidManifest.xml: the template's android:allowBackup="true" becomes false, plus two rules files -->
<application android:allowBackup="false" android:dataExtractionRules="@xml/data_extraction_rules"
             android:fullBackupContent="@xml/backup_rules"
             android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
  <cloud-backup>
    <exclude domain="file" path="faceping/" />
    <exclude domain="sharedpref" path="ai.faceping.sdk.keys.xml" />
  </cloud-backup>
  <device-transfer>
    <exclude domain="file" path="faceping/" />
    <exclude domain="sharedpref" path="ai.faceping.sdk.keys.xml" />
  </device-transfer>
</data-extraction-rules>
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
  <exclude domain="file" path="faceping/" />
  <exclude domain="sharedpref" path="ai.faceping.sdk.keys.xml" />
</full-backup-content>

On iOS there's nothing to add: FacePing keeps its folder out of iCloud and computer backups itself.

5

Turn FacePing on#

Register FacePing with your sandbox key, and register the page so it can be given IFacePing.

// MauiProgram.cs: add the using, .UseFacePing(...) and the MainPage line to what the template has
using FacePing.Sdk.Maui;

builder
    .UseMauiApp<App>()
    .UseFacePing(o => o.SandboxKey = "fp_test_…")
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    });

builder.Services.AddTransient<MainPage>();

6

Add the screen#

A camera view and two buttons (Verify in the template's colour, Enrol outlined): one enrols your face on the phone, the other verifies it.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:fp="clr-namespace:FacePing.Sdk.Maui;assembly=FacePing.Sdk.Maui"
             x:Class="FaceCheck.MainPage"
             Shell.NavBarIsVisible="False">
  <VerticalStackLayout Padding="24" Spacing="16">
    <fp:FaceCameraView x:Name="Camera" HeightRequest="420" />
    <Button Text="Enrol my face" Clicked="OnEnroll" BackgroundColor="Transparent"
            TextColor="{StaticResource Primary}" BorderColor="{StaticResource Primary}" BorderWidth="1.5" />
    <Button Text="Verify" Clicked="OnVerify" />
    <Label x:Name="Status" FontSize="18" HorizontalOptions="Center" />
  </VerticalStackLayout>
</ContentPage>
using FacePing.Sdk.Maui;

namespace FaceCheck;

public partial class MainPage : ContentPage
{
    readonly IFacePing faceping;

    public MainPage(IFacePing faceping)
    {
        InitializeComponent();
        this.faceping = faceping;
        // No camera permission, or no front camera: the message says which.
        Camera.CameraFailed += (_, message) => Status.Text = message;
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        try
        {
            // Optional: the SDK activates your sandbox key itself on first use (the first run needs a connection).
            // Syncing here shows a key problem straight away and picks up a face enrolled earlier (kept for 24 hours).
            var sync = await faceping.SyncAsync();
            // On a check-in device: who arrived, or Revoked (token revoked, mistyped or its list deleted).
            if (!faceping.IsSandbox)
                Status.Text = $"{sync.Enrolled} people synced ({sync.Status})";
        }
        catch (Exception ex) when (ex is FacePingSetupException or FacePingModelException)
        {
            Status.Text = ex.Message;
        }
    }

    async void OnEnroll(object? sender, EventArgs e)
    {
        try
        {
            var photo = await Camera.CaptureAsync();
            var result = await faceping.EnrollAsync("me", photo);
            Status.Text = result.Outcome == EnrollOutcome.Enrolled
                ? "Enrolled. Now tap Verify."
                : $"Try again: {result.Outcome}";
        }
        catch (Exception ex) when (ex is FacePingSetupException or FacePingModelException or InvalidOperationException)
        {
            // For example a mistyped key, no connection on the very first run (the sandbox key is
            // activated once), or the camera didn't deliver a picture. The message says which.
            Status.Text = ex.Message;
        }
    }

    async void OnVerify(object? sender, EventArgs e)
    {
        try
        {
            // A live check: matches your face, then asks you to turn your head (liveness).
            var result = await faceping.VerifyLiveAsync("me", Camera);
            Status.Text = $"{result.Outcome} · {result.Elapsed.TotalSeconds:0.00} s";
        }
        catch (Exception ex) when (ex is FacePingSetupException or FacePingModelException)
        {
            Status.Text = ex.Message;
        }
    }
}

7

Run it on your phone#

Plug your phone in and run a Release build (Debug builds are much slower at face checks). The first run needs a connection, to activate your sandbox key. Tap Enrol my face, then Verify: you should see Match. Use a phone: the iOS simulator has no front camera, and an Android emulator only has one if you map your computer's webcam to it in the emulator's camera settings, which is slower and less reliable for the liveness check.

dotnet build -t:Run -f net10.0-android -c Release

# Several phones connected, or installing a built app? Use adb (on macOS it's in
# ~/Library/Android/sdk/platform-tools if it isn't on your PATH):
adb devices
adb install -r bin/Release/net10.0-android/com.yourcompany.facecheck-Signed.apk
# Simulators have no front camera: use a connected iPhone. The easiest way is Run in Visual Studio
# or Rider. From the command line, build, then install with Xcode's tools (use your ApplicationId):
dotnet build -f net10.0-ios -c Release -p:RuntimeIdentifier=ios-arm64
xcrun devicectl list devices
xcrun devicectl device install app --device <device id> bin/Release/net10.0-ios/ios-arm64/FaceCheck.app
xcrun devicectl device process launch --device <device id> com.yourcompany.facecheck

First time on an iPhone? dotnet build signs the app with a provisioning profile it finds on your Mac, but it can't create one. If the build says there's no profile for your ApplicationId, make one once in Xcode: create a new iOS App project with the same bundle identifier, pick your Team under Signing & Capabilities, and run it on the phone. Then build again. A free Apple ID works too, but always needs this one-off step, and its profiles last 7 days. Allow 5 to 10 minutes for it the first time.

If you have more than one certificate or team, name the ones to use: add -p:CodesignKey="Apple Development: Your Name (XXXXXXXXXX)" and, if needed, -p:CodesignProvision="Your profile name" to the dotnet build line. security find-identity -v -p codesigning lists your certificates. On the phone, turn on Developer Mode (Settings → Privacy & Security → Developer Mode) and, if iOS says the developer isn't trusted, trust it under Settings → General → VPN & Device Management.

The Android build includes the phone (arm64) and emulator (x86_64) versions of the face engine. For a smaller app, add -p:RuntimeIdentifier=android-arm64 (phones only), or publish an Android App Bundle so each phone downloads only its own.

Now switch on airplane mode and tap Verify again. Still a match: the check ran entirely on your phone.

You've built a face check that works offline#

Next, make it real: verify the people in your app (members, visitors or people with tickets), and apply to go live when you're ready.

Try a check-in device on your practice list#

This is the ticketing flow, end to end, in the sandbox: a person enrols through your server or an enrolment link, and a check-in device verifies them offline.

  1. Create your practice list, if your account doesn't have one: New list in the dashboard asks for everything it needs, or use quickstart steps 1 and 2 (create the list, then set its widget details: enrolment links need them). Then enrol someone on it with your sandbox key: open an enrolment link (quickstart step 3; links last 30 minutes unless you pass validForHours), or enrol a selfie from your server with the copy-paste request in Enrol someone from your server. Note their personId, for example ACME-000123 (if your team shares the practice list, pick your own).
  2. Add a check-in device: the list's Devices tab in the dashboard, or POST /v1/lists/{listId}/devices. Copy the fpd_ device token: it's shown once.
  3. Check the token works before you build: curl https://api-eu.faceping.ai/v1/device -H "X-Device-Token: fpd_…" returns the list's name and peopleEnrolled. It doesn't download any faces or count as a sync.
  4. In MauiProgram.cs, swap your sandbox key for the device token: .UseFacePing(o => o.DeviceToken = "fpd_…") in place of o.SandboxKey. Building the token in is fine for this test; an app you publish pairs each device at runtime instead, with PairAsync (see Pair each device).
  5. Replace the screen with the device version. It verifies the person you enrolled, syncs when the page opens and shows every later sync. People enrol on the server, not in the app (EnrollAsync throws InvalidOperationException on a device), so there's no enrol button:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:fp="clr-namespace:FacePing.Sdk.Maui;assembly=FacePing.Sdk.Maui"
             x:Class="FaceCheck.MainPage"
             Shell.NavBarIsVisible="False">
  <VerticalStackLayout Padding="24" Spacing="16">
    <fp:FaceCameraView x:Name="Camera" HeightRequest="420" />
    <Button Text="Verify" Clicked="OnVerify" />
    <Label x:Name="Status" FontSize="18" HorizontalOptions="Center" HorizontalTextAlignment="Center" />
  </VerticalStackLayout>
</ContentPage>
using FacePing.Sdk.Maui;

namespace FaceCheck;

public partial class MainPage : ContentPage
{
    const string PersonId = "ACME-000123";   // the person you enrolled

    readonly IFacePing faceping;

    public MainPage(IFacePing faceping)
    {
        InitializeComponent();
        this.faceping = faceping;
        Camera.CameraFailed += (_, message) => Status.Text = message;
        // Show every sync: the one this page asks for, and the ones FacePing runs every few minutes.
        faceping.Synced += (_, sync) => MainThread.BeginInvokeOnMainThread(() => ShowSync(sync));
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        try
        {
            await faceping.SyncAsync();   // its result arrives through Synced too
        }
        catch (Exception ex) when (ex is FacePingSetupException or FacePingModelException)
        {
            Status.Text = ex.Message;
        }
    }

    // Revoked: the token was revoked, mistyped or its list deleted, and the device wiped its faces.
    void ShowSync(SyncResult sync) => Status.Text = $"{sync.Enrolled} people synced ({sync.Status})";

    async void OnVerify(object? sender, EventArgs e)
    {
        try
        {
            var result = await faceping.VerifyLiveAsync(PersonId, Camera);
            Status.Text = result.Outcome switch
            {
                VerifyOutcome.Match => $"Match · {result.Elapsed.TotalSeconds:0.00} s",
                VerifyOutcome.NotEnrolled => $"{PersonId} isn't on this device yet: enrol them, then wait for the next sync.",
                _ => $"Try again: {result.Outcome}"
            };
        }
        catch (Exception ex) when (ex is FacePingSetupException or FacePingModelException)
        {
            Status.Text = ex.Message;
        }
    }
}
  1. Run the app as in Run it on your phone (step 7). It downloads the list's faces at start-up and every few minutes after; the status line shows how many people synced and the sync status, and updates with each sync. Then tap Verify, with no network if you like.

Each face stays on the device no longer than its 24 hours on the practice list. See Devices and offline sync.

The finished app is ready for this: set the device token in MauiProgram.cs and PersonId at the top of MainPage.xaml.cs. It enables Verify once that person has synced to the phone and hides Enrol in device mode.

Switching one install from the sandbox key to a device token keeps the two sets of faces apart: the app sees only the people synced from the device's list, and your sandbox faces come back (if they're under 24 hours old) when you switch back. Uninstalling removes both. To keep both apps on one phone instead, make the device build in a copy of the project folder (leave out bin and obj) and give the copy its own ApplicationId, for example com.yourcompany.facecheck.device, and its own ApplicationTitle (for example FaceCheck Device), so you can tell the two apart on the home screen.