简体   繁体   English

推送通知:如何使用Pubnub将推送通知发送到特定设备?

[英]Push notification: How can I send push notification to a specific device using Pubnub?

Here is code of nodejs which I am using on server side, I am using only one chennal. 这是我在服务器端使用的nodejs的代码,我仅使用一个chennal。

Code: 码:

var pubnub = require("pubnub")({
ssl           : true,  
publish_key   : "pub-c-e2f2e008-92ce-4abc-a9fc-xxxxxxxxxxxx",
subscribe_key : "sub-c-3c272090-0370-11e5-aefa-xxxxxxxxxxxx",
geo           : true
});

exports.sendNotification=function(req,res){
var responseData={
                message:"Send notifications",
                data:null
            };

var message = {
"aps":{
    "alert":"Your Message: sent from nodejs server",
    "sound":"push1.wav"
 }
};
pubnub.publish({ 
channel   : 'apns',
message   : message,
callback  : function(e) { 
                console.log( "SUCCESS!", e );
                res.json(responseData); 
            },
error     : function(e,data) { 
                console.log( "FAILED! RETRY PUBLISH!", e ); 
                responseData.message="FAILED! RETRY PUBLISH!";
                res.json(responseData);
            }

});
}

Check this documentation . 检查此文档

Devices are registering for pushes on channel. 设备正在注册推送频道。 If you want to target specific device, you have to use multiple channels. 如果要针对特定​​设备,则必须使用多个通道。

I also suggest to use this method of sending pushes because in case of adding GCM functionality you will have to send only one message to queue that will be received by both devices 我还建议使用这种发送推送的方法,因为在添加GCM功能的情况下,您只需将一条消息发送到两个设备都将接收的队列中

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

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