使用expo-local-authentication遇认证失败:missing_usage_description问题求助
解决expo-local-authentication的"missing_usage_description"错误
问题根源
iOS平台强制要求,使用生物识别(Touch ID/Face ID)的应用必须在Info.plist中声明使用目的,未正确配置时就会触发missing_usage_description认证失败错误。
修复步骤
修正app.json配置
在项目根目录的app.json(或app.config.js)的expo.ios.infoPlist节点下,添加生物识别使用描述字段:{ "expo": { "ios": { "infoPlist": { "NSBiometricUsageDescription": "使用生物识别快速安全地登录应用", "NSFaceIDUsageDescription": "使用FaceID完成身份验证,提升登录效率" } } } }NSBiometricUsageDescription是通用生物识别描述(兼容Touch ID/Face ID)NSFaceIDUsageDescription是FaceID专属描述(可选,用于更精准的权限说明)
重启开发环境
保存配置后,执行expo start -c清除缓存并重启开发服务器,重新构建iOS项目。
优化认证流程(可选)
如果用户曾拒绝过权限,需主动请求权限后再执行认证,避免直接调用authenticateAsync失败:
import * as LocalAuthentication from 'expo-local-authentication'; // 检查并申请权限 const checkAndRequestPermission = async () => { const { status } = await LocalAuthentication.getPermissionsAsync(); if (status !== 'granted') { const { status: newStatus } = await LocalAuthentication.requestPermissionsAsync(); if (newStatus !== 'granted') { console.log('用户拒绝生物识别权限'); return false; } } return true; }; // 执行认证 const handleBiometricAuth = async () => { const hasPermission = await checkAndRequestPermission(); if (!hasPermission) return; try { const result = await LocalAuthentication.authenticateAsync({ disableDeviceFallback: true, promptMessage: 'Login with Biometrics', cancelLabel: 'Cancel' }); if (result.success) { console.log('认证成功,执行登录逻辑'); } } catch (error) { console.log('bioError:: ', error); } };
内容的提问来源于stack exchange,提问作者Mahmoud_Sabry
相关产品推荐
相关产品推荐

