0

这是我在服务器端使用的nodejs代码,我只使用一个chennal。推送通知:如何使用Pubnub向特定设备发送推送通知?

代码:

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); 
      } 

}); 
} 

回答

1

检查this documentation

设备正在注册推送频道。如果您想要定位特定设备,则必须使用多个通道。

我也建议使用this method of sending pushes因为加入GCM功能的情况下,你将不得不只发送一个消息队列,将两个设备接收