What I have done:
I have created a simple iOS native App which has nothing but OneSignal initializaion codes. I installed my App on my 2 devices, device A and device B. Both devices are subscribed to my OneSignal App Console. When I send a notification from OneSignal Web Console, the 2 devices can both recive the notification.
What I want to do:
When I click on a button on device A, device A will send a notification to device B.
What is the problem:
I followed the OneSignal iOS SDK document and created the following function https://documentation.onesignal.com/docs/ios-native-sdk#section-sending-notifications
func onButtonClick() {
OneSignal.postNotification(
[
"contents": ["en": "Test Message"],
"include_player_ids": ["c00bb8a6-79da-419b-9999-e919831a5223"] // id of device B
],
onSuccess: {(result) in print("success") },
onFailure: {(error) in print("error : \(error)") }
)
}
however, when I clicked the button, an error shows up in the xCode debug console:
2017-01-20 11:15:52.702852 my.bundle.id[2263:1201122] ERROR: Create notification failed
error : Optional(Error Domain=OneSignalError Code=400 "(null)" UserInfo={returned={
errors = (
"Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."
);
reference = (
"https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"
);
}})
I was confused, because according to the OneSignal Reference document, send notification with "include_player_ids" Does not require API Auth Key.
https://documentation.onesignal.com/reference#create-notification
And it also says: NEVER use your 'REST API key' in client code, it is intended for use on your system or server only.
So what does this error mean? And what should I do?
I even copied and run this "work without any problems" code from this discussion, but the same Authorization error still shows up. What am I doing wrong?