2

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

4

1 回答 1

12

使用 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);
于 2013-04-24T15:19:48.133 回答