React Native iOS集成OneSignal通知:添加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
相关产品推荐
相关产品推荐

