我一直在使用Titanium开发聊天应用,我在用户发送消息时发送推送通知时遇到了一些问题。
如果我只是打电话:
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)));
}
});
我从服务器上获得了
{"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"}}
但推送通知在ArrowDB面板上标有失败状态。
如果我设置to_ids = "everyone"
,则会发送推送(只要您是管理员用户),这是另一回事。
奇怪的是,如果我尝试从ArrowDB面板发送它,我会得到同样的错误。
我不确定我做错了什么,但我试图坚持钛提供的基本例子。
答案 0 :(得分:1)
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: