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

Expo推送通知在iOS模拟器无法接收的问题求助(已eject项目)

iOS 模拟器无法接收 Expo Notifications 推送排查方案

1. 先明确模拟器的推送限制

iOS模拟器本身不支持接收真实APNs推送,你拿到的Push Token是Expo专为模拟器生成的测试Token,正常服务端推送不会触发模拟器通知。测试只能用以下两种方式:

  • 执行Expo CLI命令:expo push:send --message "Test notification" --to <你的模拟器Push Token>
  • 用Xcode自带功能:点击Debug > Simulate Push Notification,导入本地编写的JSON格式推送payload文件

2. 检查iOS项目配置与原生集成

  • 核对app.json里的iOS推送配置,确保关键项齐全:
    {
      "expo": {
        "ios": {
          "bundleIdentifier": "你的项目包名",
          "infoPlist": {
            "UIBackgroundModes": ["remote-notification"],
            "NSNotificationsUsageDescription": "需要推送权限来接收消息提醒"
          }
        }
      }
    }
    
  • 确认eject后的iOS原生代码(AppDelegate.swift或AppDelegate.m)正确集成Expo Notifications:
    以Swift为例,需添加以下代码:
    import ExpoNotifications
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      // 其他初始化代码
      ExpoNotificationsAppDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
      return true
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
      ExpoNotificationsAppDelegate.shared.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
    }
    

3. 验证推送Payload格式是否合规

服务端发送的payload必须符合Expo要求,模拟器可用示例格式:

{
  "to": "<你的模拟器Push Token>",
  "sound": "default",
  "title": "测试通知",
  "body": "这是一条测试推送",
  "priority": "high"
}

如果是后台静默推送,需额外添加"content-available": 1,同时确保UIBackgroundModes已配置remote-notification。

4. 确认权限与Token状态

  • 打开模拟器的设置 > 通知 > 你的应用,检查通知权限是否完全开启(允许通知、声音、横幅等选项都要打开)
  • 验证Token有效性:向https://exp.host/--/api/v2/push/getReceipts发送GET请求,传入你的Token数组,查看返回状态是否正常

5. 检查版本兼容性

确保expo-notifications版本与eject后的React Native版本兼容,建议升级到最新稳定版,避免版本不匹配导致的隐性问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 21:44:50