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

使用expo-local-authentication遇认证失败:missing_usage_description问题求助

解决expo-local-authentication的"missing_usage_description"错误

问题根源

iOS平台强制要求,使用生物识别(Touch ID/Face ID)的应用必须在Info.plist中声明使用目的,未正确配置时就会触发missing_usage_description认证失败错误。

修复步骤

  1. 修正app.json配置
    在项目根目录的app.json(或app.config.js)的expo.ios.infoPlist节点下,添加生物识别使用描述字段:

    {
      "expo": {
        "ios": {
          "infoPlist": {
            "NSBiometricUsageDescription": "使用生物识别快速安全地登录应用",
            "NSFaceIDUsageDescription": "使用FaceID完成身份验证,提升登录效率"
          }
        }
      }
    }
    
    • NSBiometricUsageDescription是通用生物识别描述(兼容Touch ID/Face ID)
    • NSFaceIDUsageDescription是FaceID专属描述(可选,用于更精准的权限说明)
  2. 重启开发环境
    保存配置后,执行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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 02:00:20