You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何检查Touch ID的启用或禁用状态?

Hey there! Let's walk through exactly how to check Touch ID's current state—whether it's enabled, disabled, or temporarily locked out after too many failed attempts.

First, you'll need to use Apple's LocalAuthentication framework, which is the official way to interact with biometric authentication on iOS. Here's a step-by-step breakdown:

1. Import the LocalAuthentication framework

Start by adding this at the top of your file:

import LocalAuthentication

2. Use LAContext to check status

Create an instance of LAContext and use its canEvaluatePolicy(_:error:) method to determine Touch ID's availability. This method won't trigger an authentication prompt—it just checks the current state.

Here's a complete function example:

func checkTouchIDStatus() {
    let context = LAContext()
    var authError: NSError?
    
    // Check if biometric authentication (Touch ID/Face ID) is usable
    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
        // If we get here, Touch ID is enabled and ready
        print("Touch ID is active and ready for use")
        
        // Optional: Differentiate between Touch ID and Face ID (iOS 11+)
        if #available(iOS 11.0, *) {
            switch context.biometryType {
            case .touchID:
                print("Specifically, Touch ID is enabled")
            case .faceID:
                print("Face ID is enabled instead of Touch ID")
            default:
                break
            }
        }
    } else {
        // Handle the error to figure out why it's not available
        guard let error = authError as? LAError else {
            print("Unknown error checking biometric status")
            return
        }
        
        switch error.code {
        case .biometryLockout:
            print("Touch ID is temporarily locked out! The user needs to enter their device passcode to re-enable it.")
        case .biometryNotAvailable:
            print("Touch ID hardware isn't available on this device")
        case .biometryNotEnrolled:
            print("No fingerprints have been enrolled in Touch ID yet")
        case .userCancel:
            print("User canceled a previous auth prompt (this isn't a permanent disable)")
        default:
            print("Touch ID is disabled or unavailable: \(error.localizedDescription)")
        }
    }
}

Key Notes:

  • The .biometryLockout error code is exactly what you're looking for when Touch ID is disabled after 3+ failed attempts. This state persists until the user enters their device passcode (either on the lock screen or through an authentication prompt).
  • If canEvaluatePolicy returns true, Touch ID is fully enabled and functional.
  • For iOS 11 and above, you can use context.biometryType to confirm you're checking Touch ID specifically, not Face ID.

This approach covers all the scenarios you mentioned—whether Touch ID is enabled, disabled due to lockout, or unavailable for other reasons.

内容的提问来源于stack exchange,提问作者SH.LEE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:24:13