在一个连接中从node.js向多个用户发送apple推送通知

时间:2013-02-06 08:20:25

标签: node.js apple-push-notifications

我见过节点模块“node-apn”,但我看不出如何在一个连接中向多个用户发送相同的通知?我也看到可以用PHP做,但我使用的是node.js

1 个答案:

答案 0 :(得分:11)

使用node-apn v1.3.x(强烈推荐的升级),您可以向许多设备发送相同的通知,而根本不需要循环。该模块将自动处理围绕向您发送一个通知给多个设备的复杂情况。

// Instantiate a new message
// and set message defaults
var note = new apns.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "You have a new message";
note.payload = {'messageFrom': 'Caroline'};

// List of user tokens
var userTokens = ['token1', 'token2', 'token3'];
// Send the message
apnsConnection.pushNotification(note, userTokens);