What I need to implement that Face ID authentication will work on Xamarin.forms project?
Asked
Active
Viewed 2,010 times
2
-
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 Answers
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);
}

Victor Botamedi
- 134
- 9