2

What I need to implement that Face ID authentication will work on Xamarin.forms project?

Igor Strekha
  • 176
  • 3
  • 17
  • You cannot do this directly in `Xamarin Forms`, Write native `Xamarin.Android` and `Xamarin.iOS` code and then use [Dependency services](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction) to add them to your forms project. – FreakyAli Dec 05 '18 at 12:59

1 Answers1

2

You have to do this natively on your iOS project, and then expose it to your Forms project using a DependencyService or some kind of ioc.

You must add to your info.plist the NSFaceIDUsageDescription key, otherwise the app will crash when asking for authentication.

Here is a snippet that authenticates a user locally:

var context = new LAContext();
LAContextReplyHandler replyHandler;
NSError AuthError;

if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError))
{
    replyHandler = new LAContextReplyHandler((success, error) =>
    {
        // Handle authentication success or error
    });
    // Authenticate and ask for permission if needed.
    context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Authenticate", replyHandler);
}