确定iOS设备是否支持TouchID而不设置密码 [英] Determine if an iOS device supports TouchID without setting passcode

查看:93
本文介绍了确定iOS设备是否支持TouchID而不设置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款iOS应用,可让用户使用TouchID登录该应用,但首先他们必须首先在应用内设置密码。问题是,要显示设置密码选项以启用TouchID登录,我需要检测iOS设备是否支持TouchID。

I'm currently developing an iOS app that enables users to log in to the app using TouchID, but firstly they must set up a password inside the app first. Problem is, to show the setup password option to enable the TouchID login, I need to detect if the iOS device supports TouchID.

使用LAContext和canEvaluatePolicy(就像答案一样)在这里如果设备支持Touch ID ),我能够确定当前设备是否如果用户在其iOS设备上设置了密码,则支持TouchID 。这是我的代码片段(我使用的是Xamarin,所以它在C#中):

Using the LAContext and canEvaluatePolicy (like the answers in here If Device Supports Touch ID), I am able to determine whether the current device supports TouchID if the user has set up passcode on their iOS device. Here is a my code snippet (I'm using Xamarin, so it's in C#):

static bool DeviceSupportsTouchID () 
{
    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
    {
        var context = new LAContext();
        NSError authError;
        bool touchIDSetOnDevice = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError);

        return (touchIDSetOnDevice || (LAStatus) Convert.ToInt16(authError.Code) != LAStatus.TouchIDNotAvailable);
    }

    return false;
}

如果用户尚未设置设备密码,无论设备是否实际支持TouchID,authError都会返回 PasscodeNotSet 错误。

If the user has not set up the device passcode, the authError will just return "PasscodeNotSet" error regardless of whether the device actually supports TouchID or not.

如果用户的设备支持TouchID,我想在我的应用中始终显示TouchID选项,无论用户是否在他们的设备上设置了密码(我都会发出警告)用户首先在他们的设备上设置密码)。反之亦然,如果用户的设备不支持TouchID,我显然不想在我的应用程序中显示TouchID选项。

If the user's device supports TouchID, I want to always show the TouchID option in my app regardless of whether the user has set up passcode on their device (I will just warn the user to setup passcode on their device first). Vice versa, if the user's device doesn't support TouchID, I obviously don't want to show the TouchID option in my app.

所以我的问题是,是否有无论用户是否在其设备上设置密码,一致地确定iOS设备是否支持TouchID的好方法是什么?

So my question is, is there a nice way to consistently determine whether an iOS device supports TouchID regardless of whether the user has set up passcode on their device?

我能想到的唯一解决方法是确定设备的体系结构(在确定iOS设备是否可用)是32位或64位),因为只有具有64位架构的设备才支持TouchID。但是,我正在寻找是否有更好的方法来做到这一点。

The only workaround I can think of is to determine the architecture of the device (which is answered in Determine if iOS device is 32- or 64-bit), as TouchID is only supported on devices with 64-bit architecture. However, I'm looking if there's any nicer way to do this.

事先谢谢! :)

推荐答案

在下面的讨论结束时,暂时无法确定设备是否实际支持TouchID或者当用户没有在他们的设备上设置密码时。

In conclusion of the discussion below, for the time being it is not possible to determine whether a device actually supports TouchID or not when the user hasn't set up passcode on their device.

我在Apple bug报告器上报告了这个TouchID缺陷。那些想要关注这个问题的人可以在Open Radar上看到它: http://www.openradar.me/20342024

I have reported this TouchID flaw on the Apple bug reporter. Those who want to follow the issue can see it on Open Radar here: http://www.openradar.me/20342024

感谢@rckoenes的输入:)

Thanks @rckoenes for the input :)

编辑

原来有人报告了类似的问题(#18364575)。以下是Apple对此问题的回复:

Turns out that someone has reported a similar issue already (#18364575). Here is Apple's reply regarding the issue:

工程已根据以下信息确定此问题的行为符合预期:

如果未设置密码,您将无法检测Touch ID的存在。一旦设置了密码,canEvaluatePolicy将最终返回LAErrorTouchIDNotAvailable或LAErrorTouchIdNotEnrolled,您将能够检测触摸ID存在/状态。

如果用户在具有Touch ID的手机上禁用了密码,他们就知道他们将无法使用触摸ID,因此应用无需检测Touch ID状态或推广基于Touch ID的功能。

所以......最终Apple的回答是。 :(

So..... the final answer from Apple is No. :(

注意:来自报告此事的人的类似StackOverflow问题 - > iOS8检查设备是否有Touch ID
(想知道为什么我之前没有找到这个问题,尽管我进行了广泛的搜索......)

Note: similar StackOverflow question from the person who reported this -> iOS8 check if device has Touch ID (wonder why I didn't find this question before despite my extensive searching...)

这篇关于确定iOS设备是否支持TouchID而不设置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆