Determine if an iOS device supports TouchID without setting passcode

前端 未结 7 1769
一生所求
一生所求 2020-12-25 13:27

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

7条回答
  •  清酒与你
    2020-12-25 14:14

    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.

提交回复
热议问题