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

查看:28
本文介绍了在不设置密码的情况下确定 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(就像这里的答案如果设备支持触控 ID),我可以确定当前设备是否支持 TouchID 如果用户在他们的 iOS 设备上设置了密码.这是我的代码片段(我使用的是 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 漏洞报告器上报告了这个 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,您将能够检测到 Touch ID 的存在/状态.

如果用户在带有 Touch ID 的手机上禁用了密码,他们知道他们将无法使用 Touch ID,因此应用程序不需要检测 Touch ID 的存在或推广基于 Touch ID 的功能.

所以..... Apple 的最终答案是.:(

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

注意:来自报告此人的类似 StackOverflow 问题 -> iOS8 检查如果设备有触控 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天全站免登陆