How to enable Face ID on Xamarin.iOS
15 Jan 2019With iPhone X, Apple release a new biometric authentication way: Face ID. Like others things, you need to obtain access to that feature. To achieve this, you must add the NSFaceIDUsageDescription
key to the info.plist file:
The, optional, description will be good if you want to explain why your app request the ability to authenticate with Face ID.
After that, you will be able to use Face ID authentication:
var context = new LAContext();
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError authError))
{
var replyHandler = new LAContextReplyHandler((success, error) =>
{
InvokeOnMainThread(() =>
{
if (success)
{
// user authenticated
}
else
{
// user not authenticated
}
});
});
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Authenticate", replyHandler);
}
the above code will works for both Touch ID and Face ID.
Enjoy!