This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo LocalAuthentication
一个库,提供实现指纹 API(Android)或 FaceID 和 TouchID(iOS)的功能,以通过面部或指纹扫描验证用户身份
expo-local-authentication 允许你使用生物识别提示(Android)或 FaceID 和 TouchID(iOS),通过指纹或面部扫描对用户进行身份验证。
已知限制
iOS iOS
iOS 的 FaceID 身份验证不支持在 Expo Go 中使用。你需要创建一个开发版本来测试 FaceID。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
在应用配置中进行配置
如果你的项目使用配置插件(持续原生生成(CNG)),则可以使用内置的配置插件来配置 expo-local-authentication。该插件允许你配置无法在运行时设置、且需要构建新的应用二进制文件才能生效的各种属性。如果你的应用不使用 CNG,则需要手动配置该库。
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
如果你不使用持续原生生成(CNG),或者手动使用原生 ios 项目,则需要将 NSFaceIDUsageDescription 键添加到 ios/[app]/Info.plist 中:
API
import * as LocalAuthentication from 'expo-local-authentication';
Methods
Attempts to authenticate via Fingerprint/TouchID (or FaceID if available on the device).
Note: Apple requires apps which use FaceID to provide a description of why they use this API. If you try to use FaceID on an iPhone with FaceID without providing
infoPlist.NSFaceIDUsageDescriptioninapp.json, the module will authenticate using device passcode. For more information about usage descriptions on iOS, see permissions guide.
Promise<LocalAuthenticationResult>Returns a promise which fulfils with LocalAuthenticationResult.
Cancels authentication flow.
Promise<void>Determine what kind of authentication is enrolled on the device.
Promise<SecurityLevel>Returns a promise which fulfils with SecurityLevel.
Note: On Android devices prior to M,
SECRETcan be returned if only the SIM lock has been enrolled, which is not the method thatauthenticateAsyncprompts.
Determine whether a face or fingerprint scanner is available on the device.
Promise<boolean>Returns a promise which fulfils with a boolean value indicating whether a face or
fingerprint scanner is available on this device.
Determine whether the device has saved fingerprints or facial data to use for authentication.
Promise<boolean>Returns a promise which fulfils to boolean value indicating whether the device has
saved fingerprints or facial data for authentication.
Determine what kinds of authentications are available on the device.
Promise<AuthenticationType[]>Returns a promise which fulfils to an array containing AuthenticationTypes.
Devices can support multiple authentication methods - i.e. [1,2] means the device supports both
fingerprint and facial recognition. If none are supported, this method returns an empty array.
Types
Literal type: string
Security level of the biometric authentication to allow.
Acceptable values are: 'weak' | 'strong'
Literal type: string
One of the error values returned by the LocalAuthenticationResult object.
Acceptable values are: 'not_enrolled' | 'user_cancel' | 'app_cancel' | 'not_available' | 'lockout' | 'no_space' | 'timeout' | 'unable_to_process' | 'unknown' | 'system_cancel' | 'user_fallback' | 'invalid_context' | 'passcode_not_set' | 'authentication_failed'
Enums
SecurityLevel.BIOMETRIC_WEAK = 2Indicates weak biometric authentication. For example, a 2D image-based face unlock.
There are currently no weak biometric authentication options on iOS.
权限
Android
此库会自动通过其 AndroidManifest.xml 添加以下权限:
iOS
此库使用以下使用说明键: