问题
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