如何在iPhone中一次性向多个设备发送推送通知? [英] How can I send push notification to multiple devices in one go in iPhone?

查看:338
本文介绍了如何在iPhone中一次性向多个设备发送推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我当前的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无法连接$ err $ errstr\ n;
返回;
}
$ msg = chr(0)。包(n,32)。 pack('H *',str_replace('','',$ deviceToken))。 pack(n,strlen($ payload))。 $有效载荷;
fwrite($ fp,$ msg);


解决方案

一句话,你不能即可。您需要向每个令牌发送消息。


就像电子邮件一样,可以有多个收件人。


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




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


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



I want to send same messages to all devices who are registered with application but how can send them without making multiple connections...

My current PHP code:

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

解决方案

Bottom line, you can't. You need to send a message to each token.

Its not working like a email where you can have multiple recipients.

Once the connection is open you can send a bunch of messages, thats also the preferred way (based on Apples SDK).

from the SDK:

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

You should also retain connections with APNs across multiple notifications. APNs may consider connections that are rapidly and repeatedly established and torn down as a denial-of-service attack. Upon error, APNs closes the connection on which the error occurred.

这篇关于如何在iPhone中一次性向多个设备发送推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆