Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if an iOS device supports TouchID without setting passcode

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.

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;
}

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.

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.

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?

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.

like image 988
ABVincita Avatar asked Mar 26 '15 13:03

ABVincita


People also ask

Can you use Touch ID without passcode?

Answer: A: No. To even be able to set up fingerprint recognition, you must first setup a passcode. This is required when you reset the device, or whenever you have not used your fingerprint for more than 48hrs.

Which iPad has Touch ID?

iPad Pro. iPad (5th generation and later) iPad Air 2. iPad mini 3 or later.

Why does my thumb print not work on my iPhone?

Make sure that you have the latest version of iOS or iPadOS. Make sure that your fingers and the Touch ID sensor are clean and dry. * For the Touch ID sensor, use a clean, lint-free cloth to wipe off any dirt or debris. Your finger should cover the Touch ID sensor completely, touching the surrounding metal ring.


2 Answers

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.

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

Thanks @rckoenes for the input :)

EDIT

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

"Engineering has determined that this issue behaves as intended based on the following information:

If passcode is not set, you will not be able to detect Touch ID presence. Once the passcode is set, canEvaluatePolicy will eventually return LAErrorTouchIDNotAvailable or LAErrorTouchIdNotEnrolled and you will be able to detect Touch ID presence/state.

If users have disabled passcode on phone with Touch ID, they knew that they will not be able to use Touch ID, so the apps don't need to detect Touch ID presence or promote Touch ID based features. "

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

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...)

like image 104
ABVincita Avatar answered Sep 22 '22 08:09

ABVincita


The correct way to detect if TouchID is available:

BOOL hasTouchID = NO;
// if the LAContext class is available
if ([LAContext class]) {
    LAContext *context = [LAContext new];
    NSError *error = nil;
    hasTouchId = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
}

Sorry it is in Objective-C, you might have to translate it to C#.

You should refrain from checking the system version and just check whether or not the class or methods are available.

like image 20
rckoenes Avatar answered Sep 20 '22 08:09

rckoenes