Reputation: 2474
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);
Upvotes: 4
Views: 12388
Reputation: 7612
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:
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.
Upvotes: 10
Reputation: 5892
You can use one connection to send multiple messages, so you don't need to open multiple connections. You can't use one message for multiple devices.
Upvotes: 3