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

构建APK后Expo Notifications无法接收通知求助

解决Expo Notifications在APK构建后无法接收通知的问题

以下是针对性的排查和修复步骤:

1. 确认app.json中的权限与插件配置

确保app.json包含必要的通知权限(尤其是Android 13+所需的POST_NOTIFICATIONS),并正确配置expo-notifications插件:

{
  "expo": {
    "plugins": [
      [
        "expo-notifications",
        {
          "icon": "./assets/notification-icon.png",
          "color": "#ffffff",
          "channelId": "default",
          "androidNotificationChannelName": "Default Channel"
        }
      ]
    ],
    "android": {
      "permissions": [
        "ACCESS_NOTIFICATION_POLICY",
        "POST_NOTIFICATIONS"
      ],
      "useNextNotificationsApi": true
    }
  }
}

2. 重新验证FCM密钥上传状态

重新执行密钥上传命令,确保输出提示成功:

expo push:android:upload --api-key <你的FCM服务器密钥>

完成后检查Expo项目控制台的Push Notifications配置,确认Android服务器密钥已正确关联。

3. 调整通知渠道创建时机

将通知渠道创建逻辑移到权限请求之前,确保应用启动时就完成渠道初始化(Android 8.0+必须有渠道才能显示通知):

async function registerForPushNotificationsAsync() {
  let token;

  // 优先创建通知渠道
  if (Platform.OS === "android") {
    await Notifications.setNotificationChannelAsync("default", {
      name: "default",
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: "#FF231F7C",
      sound: "default"
    });
  }

  // 后续权限请求与令牌获取逻辑保持不变...
}

4. 调试APK中的令牌与通知监听

在APK中添加详细日志,确认令牌获取和监听器状态:

// 在registerForPushNotificationsAsync中补充日志
token = await Notifications.getExpoPushTokenAsync({
  projectId: "b37ba3bc-286c-43a3-b3f2-ae2fa40ca6cd",
});
console.log("APK推送令牌:", token.data);

通过adb logcat *:S ReactNative:V ReactNativeJS:V命令查看APK运行日志,排查是否存在权限申请失败、令牌获取错误等问题。

5. 检查设备端通知设置

手动进入设备的应用设置,确认:

  • 应用通知权限已完全开启
  • default通知渠道未被禁用或静音
  • Android 13+设备已授予POST_NOTIFICATIONS权限

6. 发送测试通知验证

使用APK获取的专属令牌发送测试通知,而非Expo Go的令牌:

expo push:send --message "测试通知" --token <APK获取的令牌>

若仍未收到,查看Expo控制台的推送记录,确认是否存在令牌无效、FCM配置错误等提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 05:47:05