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

Pra*_*abh 4 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);
Run Code Online (Sandbox Code Playgroud)

Rog*_*ger 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会关闭发生错误的连接.