检查设备在 Xamarin iOS 中是否具有本地身份验证 微软文档

问题描述

我需要检查苹果设备是否在我的 xamarin.iOS 项目中激活了某种身份验证方法。例如在我的 xamarin Android 项目中,我可以这样做:

public bool ExistsLocalAuthenticacion() {
   KeyguardManager keyguardManager = (KeyguardManager)Android.App.Application.Context.GetSystemService("keyguard");
   if (keyguardManager.IsDeviceSecure)
      return true;
   else
      return false;
}

我需要做类似的事情,但在 iOS 项目中,这可能吗?

解决方法

CanEvaluatePolicy() 上使用 deviceOwnerAuthentication

var context = new LAContext();
if (context.CanEvaluatePolicy(LAPolicy.deviceOwnerAuthentication,out var error))
{
    return true;
}
else
{
    return false;
    //handle error
}

微软文档

Use Touch ID and Face ID with Xamarin.iOS