如何在城市飞艇中设置多个观众

时间:2015-10-19 09:57:42

标签: php android ios push-notification urbanairship.com

我正在使用php客户端向城市飞艇发送通知请求。 为此,我在下面提到了链接。
https://support.urbanairship.com/entries/70144047-Simple-PHP-API-v3-examples
因为观众被设置为

$push = array("audience"=>"all", "notification"=>$notification, "device_types"=>$platform);

我想发送通知,以便选择iOS和Android设备。 为此,我正在为iOS和Android创建一个数组。 像这样。

$iosDevices = array(); 
array_push($iosDevices, "Channel_id_for_iOS_device_1"); 
array_push($iosDevices, "Channel_id_for_iOS_device_2"); 
$main__channel['ios_channel'] = $iosDevices;
$push = array("audience"=>  $main__channel,"notification"=>$notification, "device_types"=>$platform);

这很好用,但是当我尝试添加android的频道ID数组时,它不允许我这样做。

$androidDevices = array(); 
array_push($androidDevices, "Channel_id_for_android_device_1"); 
array_push($androidDevices, "Channel_id_for_android_device_2"); 
$main_channel['android_channel'] = $androidDevices; 
$push = array("audience"=> $main__channel,"notification"=>$notification, "device_types"=>$platform);

我想向iOS和Android设备ID发送通知(仅选择一个)。
我希望将这些阵列传递给观众。有没有办法这样做?

响应

  

{" ok":false,"错误":"无法解析请求   正文。"," error_code":40210,"详情":{"错误":"指定多个   选择器的类型(' android_channel'是   意想不到)""路径":" audience.android_channel [0]""位置" {"线&#34 ;: 1,"柱" 127}}," operation_id":" 2b00a2a0-73cd-11e5-a4ba-90e2ba2901f0"}   得到了服务器的否定回复:40

1 个答案:

答案 0 :(得分:1)

得到了城市飞艇支持的答复。以下是答案。

"audience": {
      "OR": [
         { "ios_channel": [ 
            "Channel_id_for_iOS_device_1", 
            "Channel_id_for_iOS_device_1" 
         ] },
         { "android_channel": [ 
            "Channel_id_for_android_device_1", 
            "Channel_id_for_android_device_2", 
            "Channel_id_for_android_device_3" 
         ] }
      ]
   }

我测试了它,它适用于iOS和Android。