简体   繁体   English

使用 Cloud.PushNotifications.notify 向特定 ID 发送推送通知后失败

[英]Failure after sending push notification to specific IDs with Cloud.PushNotifications.notify

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.我一直在用 Titanium 开发一个聊天应用程序,当用户发送消息时我在发送推送通知时遇到了一些问题。

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我从服务器得到了 OK

    {"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.但推送通知在 ArrowDB 面板上标有状态失败

A different story if I set to_ids = "everyone" , the push is sent (as long as you're an admin user).如果我设置为to_ids = "everyone" ,则会发送推送(只要您是管理员用户)。

The weird thing is that I get the same error if I try to send it from the ArrowDB panel.奇怪的是,如果我尝试从 ArrowDB 面板发送它,我会得到同样的错误。

Sending the push with specific IDs使用特定 ID 发送推送使用特定 ID 发送推送

Sending the push to everone向所有人发送推送向所有人发送推送

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 .经过大量测试后,我意识到在Cloud.Users.login方法之后我错误地调用了Cloud.PushNotifications.subscribeToken而不是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:编辑:我没有注意到悬停失败标签向您展示了原因(显示信息的一种有点奇怪的方式),实际上原因在那里有所解释:

错误信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM