Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Push Notification to multiple devices?

Tags:

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.

like image 429
Yogi Avatar asked Apr 12 '11 04:04

Yogi


2 Answers

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?

like image 194
Priyank Avatar answered Sep 21 '22 12:09

Priyank


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.

like image 27
DigiMee Avatar answered Sep 20 '22 12:09

DigiMee