This is the first time I am using push notification in my App. I have gone through sample applications along with books and I got how to send push notification to a single device. But I am not getting exactly what changes should I do in my program to send push notification to multiple devices. I am using 'PushMeBaby' application for server side coding. Please, help me out.
Try this example code and modify for your environment.
$apnsHost = '<APNS host>'; $apnsPort = <port num>; $apnsCert = '<cert>'; $streamContext = stream_context_create(); stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext); $payload['aps'] = array('alert' => 'some notification', 'badge' => 0, 'sound' => 'none'); $payload = json_encode($payload); // Note: $device_tokens_array has list of 5 devices' tokens for($i=0; $i<5; $i++) { $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_tokens_array[i])) . chr(0) . chr(strlen($payload)) . $payload; fwrite($apns, $apnsMessage); }?>
This article helps verifying drop connection and connection status: Apple Push Notification: Sending high volumes of messages
Other reference links:
How can I send push notification to multiple devices in one go in iPhone? and how to handle multiple devices when using Push Notification?
I found that you have to create a new stream_context_create for each fwrite to prevent apple from closing the connection for a bad token.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With