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

React Native iOS集成OneSignal通知:添加Action Button问题求助

解决iOS模拟器中APNS通知Action Button不显示的问题

问题根源

你当前的APNS payload格式错误:actionButtons不是aps.alert下的合法字段,APNS的通知动作按钮需要通过预注册通知类别,再在payload中用category字段关联才能生效。

步骤1:在React Native项目中注册通知类别

先通过OneSignal API注册对应的通知类别,确保App启动时完成注册:

OneSignal.setNotificationCategories([
  {
    id: "test_category",
    actions: [
      {
        id: "test",
        text: "Test",
      },
    ],
  },
]);

步骤2:正确的APNS测试Payload

修改后的JSON格式如下,核心是将category放在aps根节点下,与预注册的类别ID对应:

{
  "Simulator Target Bundle": "你的Bundle ID",
  "aps": {
    "alert": {
      "title": "Push Notification",
      "subtitle": "Test Push Notifications",
      "body": "Testing Push Notifications on iOS Simulator"
    },
    "category": "test_category"
  },
  "custom": {
    "i": "notificationId as UUID",
    "a": {"deeplinkKey": "{\"deeplinkDetailKey\":\"deeplinkDetailValue\"}", "launchURL": "example://collection/myCollectionId/type/1"}
  }
}

注意事项

  • category的值必须和你注册的通知类别ID完全一致,系统才能匹配并显示动作按钮。
  • 测试前确保App已经启动过,完成了通知权限申请和类别注册流程。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 23:55:00