【问题标题】:How to use FaceID using Xamarin.forms?如何使用 Xamarin.forms 使用 FaceID?
【发布时间】:2018-12-05 09:47:25
【问题描述】:
在 Xamarin.forms 项目中实现 Face ID 身份验证需要什么?
【问题讨论】:
-
您不能直接在Xamarin Forms 中执行此操作,请编写本机Xamarin.Android 和Xamarin.iOS 代码,然后使用Dependency services 将它们添加到您的表单项目中。
标签:
authentication
xamarin.forms
face-id
【解决方案1】:
您必须在您的 iOS 项目中本地执行此操作,然后使用 DependencyService 或某种 ioc 将其公开给您的 Forms 项目。
您必须将NSFaceIDUsageDescription 密钥添加到您的info.plist,否则应用程序在请求身份验证时会崩溃。
这是一个在本地对用户进行身份验证的 sn-p:
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);
}