如何在iPhone中一次性向多个设备发送推送通知?

时间:2011-02-19 10:56:15

标签: php iphone push-notification

我想向所有使用应用程序注册的设备发送相同的消息但是如何在不进行多重连接的情况下发送它们...

我目前的PHP代码:

ctx = stream_context_create();  
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');  
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);  
if (!$fp)
{
  print "Failed to connect $err $errstr\n";
  return;
}
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
fwrite($fp, $msg);

2 个答案:

答案 0 :(得分:10)

底线,你不能。您需要向每个令牌发送一条消息。

  

的工作方式类似于您可以拥有多个收件人的电子邮件。

连接打开后,您可以发送大量消息,也就是首选方式(基于Apples SDK)。

来自SDK的

http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW2

  

您还应该在多个通知中保留与APN的连接。 APN可以考虑快速重复建立的连接,并将其拆除为拒绝服务攻击。出错时,APN会关闭发生错误的连接。

答案 1 :(得分:3)

您可以使用一个连接发送多条消息,因此您无需打开多个连接。您不能将一条消息用于多个设备。