OneSignal push notification to all segments

半腔热情 提交于 2019-12-14 02:50:51

问题


I am trying to send push notification from the admin device, to all devices (segment:"ALL"). I can't seem to get it to work with this code.

let data = [
    "contents": ["en": "\(message)"],
    "included_segments": ["All"],
    "excluded_segments": ["None"],
    "ios_badgeType": "Increase",
    "ios_badgeCount": 1
]

OneSignal.defaultClient().postNotification(data)

The "None" segment exists and has 0 users in it. "All" has all active users.

When I post the notification I get an error

ERROR: Create notification failed

while this does work without any problems:

let data = [
    "contents": ["en": "\(message)"],
    "include_player_ids":["20a32b7a-4254-4e03-a24c-13fe8bd91fff"],
    "ios_badgeType": "Increase",
    "ios_badgeCount": 1
]

OneSignal.defaultClient().postNotification(data)

回答1:


You can only use include_player_ids from postNotification as other targeting parameters like included_segments require your OneSignal App REST API key.

If you need to target all users you should first make a call to your server from your app where you can safely use the create notification REST API POST call.



来源:https://stackoverflow.com/questions/38160677/onesignal-push-notification-to-all-segments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!