I've been developing a chat app with Titanium and I'm facing some issues while sending push notifications when a user send a message.
If I simply call:
Cloud.PushNotifications.notify({
channel : 'myChannel',
to_ids : usersID.toString(),
payload : {
message : "message",
from : myId,
sound : "default",
alert : "New message!",
}
};, function(e) {
if (e.success) {
console.log('Success');
} else {
console.log('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
I get the OK from the server
{"push_notification":{"id": "xxx", "payload": "{\"message\":\"message\",\"from\":\"xxx\",\"sound\":\"default\",\"alert\":\"New message!\"}", "channel": "myChannel"}, "success": true,"error": false, "meta":{"code": 200, "status": "ok", "method_name": "Notify"}}
but the push notification is marked with the status Failure on the ArrowDB panel.
A different story if I set to_ids = "everyone"
, the push is sent (as long as you're an admin user).
The weird thing is that I get the same error if I try to send it from the ArrowDB panel.
Sending the push with specific IDs
I'm not sure what I'm doing wrong but I tried to stick to the basic examples provided by titanium.
The problem was that the devices didn't have an user associated:
After a lot of tests I realized that after the Cloud.Users.login
method I was wrongly calling the method Cloud.PushNotifications.subscribeToken
instead of the Cloud.PushNotifications.subscribe
. Changing that, after the login and subscribe, the device has an user associated to it:
And everything works as expected, push notifications are sent and received.
EDIT: I didn't notice that hovering the Failure label showed you the reason (a little weird way to show info), and the reason in fact was somewhat explained in there: