我需要什么来实现 Face ID 身份验证才能在 Xamarin.forms 项目上运行?
最佳答案
您必须在 iOS 项目上本地执行此操作,然后使用 DependencyService
或某种 ioc 将其公开给您的 Forms 项目。
您必须将 NSFaceIDUsageDescription
键添加到您的 info.plist
中,否则应用程序在请求身份验证时会崩溃。
以下是在本地验证用户身份的代码片段:
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);
}
关于authentication - 如何使用 Xamarin.forms 使用 FaceID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53629371/