3

In a multicast GCM trigger, I want to send different payload to each user. My GCM json corresponding array is as follows:

$fields = array(
'collapse_key' => 'demo',
'registration_ids' => $registration_ids,
'data' => array('myjson' => 'abc'),
);

Consider the registeration_ids array as follows:

$registration_ids => array('id1','id2','id3');

With the above mentioned GCM json corresponding array, all the users get same value of 'myjson'. Is there any way that i can design the json corresponding array such that 'id1' gets 'abc' as the value of 'myjson', 'id2' gets 'def' as the value of 'myjson'... and so on?

Eran
  • 387,369
  • 54
  • 702
  • 768
Ammad
  • 55
  • 6
  • multicast means sending the same message to multiple users in a single request, you can't multicast for this. – manubkk Jul 18 '13 at 03:55

2 Answers2

3

It's not possible. A multicast message allows you only to send the same message to multiple registration IDs.

  • A 3rd-party application server can either send messages to a single device or to multiple devices. A message sent to multiple devices simultaneously is called a multicast message.
  • To send a single message to multiple devices owned by a single user, you can use a notification_key, as described in User Notifications.
  • You have 2 choices in how you construct requests and responses: plain text or JSON.
  • However, to send multicast messages, you must use JSON. Plain text will not work.

registration_ids A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). A request must include a recipient—this can be either a registration ID, an array of registration IDs, or a notification_key.

Note that in a multicast message you are still sending a single message. The only parameter that can have multiple values in the JSON request is the registration_ids.

To send different messages to different devices, you must send one request (either JSON with a single registration ID or plain text) for each device.

Eran
  • 387,369
  • 54
  • 702
  • 768
-2

Make it a map like this:

{
  regn: [{
          regn_id: id_1,
          data: abc
         },
         {
          regn_id: id_2,
          data: defg
         },
       ..]
}

Call it in a JSONArray object.

curlyreggie
  • 1,530
  • 4
  • 21
  • 31