Android GCM - 向registration_ids数组中的每个用户发送不同的有效内容 [英] Android GCM - Send different payload to each user in registration_ids array
问题描述
在多播GCM触发器中,我想向每个用户发送不同的有效载荷。
我的GCM json对应的数组如下所示:
$ $ $ $ $ $ $ $ $ $ $ $ $ $'$'$'$'$'$' ''demo',
'registration_ids'=> $ registration_ids,
'data'=>数组('myjson'=>'abc'),
);
请考虑registeration_ids数组,如下所示:
$ registration_ids =>阵列( ID1’ , ID2’ , ID3’ );
使用上面提到的GCM json对应的数组,所有用户都得到相同的'myjson'值。有没有什么办法可以设计json对应的数组,使'id1'获得'abc'作为'myjson'的值,'id2'获得'def'作为'myjson'的值...等等?
这是不可能的。多播消息只允许您将相同的消息发送到多个注册ID。
- 第三方应用程序服务器可以将消息发送到单个设备或多个设备。同时发送到多个设备的消息称为多播消息。
- 要将单条消息发送给单个用户拥有的多个设备,可以使用notification_key,如用户通知中所述。
- 您在构建请求和响应的方式上有两种选择:纯文本或JSON。
- 但是,要发送多播消息,必须使用JSON 。纯文本不起作用。
registration_ids 接收设备列表(注册ID)的字符串数组讯息。它必须包含至少1个和最多1000个注册ID。要发送组播消息,您必须使用JSON。为了将单条消息发送到单个设备,您可以使用仅有1个注册ID或纯文本的JSON对象(请参见下文)。请求必须包含收件人 - 可以是注册ID,注册ID数组或注册ID。
请注意,在多播消息中,您仍然发送单个消息。在JSON请求中可以有多个值的唯一参数是 registration_ids
。
要将不同的消息发送到不同的消息设备,您必须为每个设备发送一个请求(带有单个注册ID的JSON或纯文本)。
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?
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.
这篇关于Android GCM - 向registration_ids数组中的每个用户发送不同的有效内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!