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

iOS调用getExpoPushTokenAsync()报错:未找到experienceId或projectId

解决Expo React Native推送令牌获取错误:No experienceId or projectId found

问题重现

调用Notifications.getExpoPushTokenAsync()时触发错误:

No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself

已完成FCM和APNs配置并关联Expo项目,当前仅在iOS端测试。

解决方案

1. 手动传入Project ID

从expo.dev你的项目页面复制Project ID,调用接口时显式传入:

import * as Notifications from 'expo-notifications';

const fetchPushToken = async () => {
  try {
    const tokenResponse = await Notifications.getExpoPushTokenAsync({
      projectId: '你的Expo项目ID', // 替换为实际项目ID
    });
    console.log('推送令牌:', tokenResponse.data);
  } catch (err) {
    console.error('获取令牌失败:', err);
  }
};

这是最直接的修复方式,尤其适用于bare workflow或manifest信息无法自动加载的场景。

2. 检查Expo配置文件完整性

确保app.json/app.config.js的expo字段包含必要信息,Expo依赖这些生成experienceId:

{
  "expo": {
    "name": "你的应用名称",
    "slug": "应用唯一标识slug",
    "owner": "你的Expo账号用户名",
    "ios": {
      "bundleIdentifier": "com.yourcompany.yourapp",
      "infoPlist": {
        "UIBackgroundModes": ["remote-notification"]
      }
    },
    "android": {
      "package": "com.yourcompany.yourapp",
      "googleServicesFile": "./google-services.json"
    }
  }
}

如果是bare workflow,需确保expo-updates模块已正确安装并配置,它负责加载manifest元数据。

3. 验证本地项目与Expo账号的关联

  • 执行expo whoami确认当前登录的Expo账号与项目所属账号一致
  • 执行expo config查看本地配置,核对projectId是否与expo.dev上的项目ID匹配

4. 确认iOS推送配置细节

  • 检查Apple开发者后台的APNs推送证书是否有效,并已上传至expo.dev项目的iOS设置页面
  • 确保iOS设备已开启应用的推送权限(设置→通知→你的应用,确认允许通知)
  • 验证infoPlist中UIBackgroundModes包含remote-notification,保证应用后台接收推送的能力

内容的提问来源于stack exchange,提问作者BetaBites

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 21:35:09