简体   繁体   中英

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.

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使用特定 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 . 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:

错误信息

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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