【发布时间】:2018-02-16 16:18:56
【问题描述】:
我们正在尝试使用我们的 Xamarin Forms 应用程序在 iOS 中使用 Touch Id。
在我们的 Xamarin Forms 应用程序中,在 App.Xaml.cs 构造函数中,我们使用一个接口来引用 iOS 本机触摸 ID 实现:
bool _authenticatedWithTouchID = DependencyService.Get<ITouchID>().AuthenticateUserIDWithTouchID();
if (_authenticatedWithTouchID)
{
MainPage = new NavigationPage(new MainPage());
}
else
{
MainPage = new NavigationPage(new LoginPage());
}
这是表单应用程序中的接口签名:
public interface ITouchID
{
bool AuthenticateUserIDWithTouchID();
}
这是iOS项目中接口的实现:
[assembly: Dependency(typeof(TouchID))]
namespace GetIn.iOS
{
public class TouchID : ITouchID
{
public bool AuthenticateUserIDWithTouchID()
{
bool outcome = false;
var context = new LAContext();
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError AuthError))
{
var replyHandler = new LAContextReplyHandler((success, error) => {
Device.BeginInvokeOnMainThread(() => {
if (success)
{
outcome = true;
}
else
{
outcome = false;
}
});
});
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Logging with touch ID", replyHandler);
};
return outcome;
}
}
}
我们从结果变量中得到一个响应(如果用户通过了身份验证,则为真),但它没有被传递回表单应用程序。
我们也尝试过使用异步任务,但没有成功。
我们有推荐的方法吗?我们正努力让这一切尽可能简单。
【问题讨论】:
-
Ajam,你可以查看这篇关于它的文章somostechies.com/fingerprint
-
您好,感谢您的回复,我们正在为我们的代码寻找解决方案,而不是使用插件。
-
您需要一个 taskcompletionsource,因为您的代码是异步的,但您的编码就像是同步的一样。
标签: c# xamarin xamarin.forms xamarin.ios touch-id