Urban Airship - send PUSH to 1 specific device (device token)

南笙酒味 提交于 2019-12-04 15:43:46

问题


So I want to target one specific device token via Urban Airship, but no matter what I do, all of my devices get the message intended for a specific device token.

Here's my PHP code - any help is as usual greatly appreciated!

define('APPKEY','XXXXXXXXXXXXXX'); 
define('PUSHSECRET', 'XXXXXXXXXXXXX '); // Master Secret
define('PUSHURL', 'https://go.urbanairship.com/api/push/broadcast/'); 


$msg = "This is a message intended for my iPad 3";

    $devicetokens = array();
$devicetokens[0] = $devicetoken;

 $contents = array(); 
 $contents['badge'] = "1"; 
 $contents['alert'] = $msg; 
 $contents['sound'] = "default"; 

 $push = array("aps" => $contents, "device_tokens" =>$devicetokens); 



 //var_dump($push);


 $json = json_encode($push); 

 $session = curl_init(PUSHURL); 
 curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET); 
 curl_setopt($session, CURLOPT_POST, True); 
 curl_setopt($session, CURLOPT_POSTFIELDS, $json); 
 curl_setopt($session, CURLOPT_HEADER, False); 
 curl_setopt($session, CURLOPT_RETURNTRANSFER, True); 
 curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); 
 $content = curl_exec($session); 
 //var_dump($content); // just for testing what was sent

 // Check if any error occured 
 $response = curl_getinfo($session);

回答1:


The URL you're using is for broadcasting. To send notification to specific devices, the url you should use is 'https://go.urbanairship.com/api/push/'




回答2:


Urban Airship have provided sample PHP code to overcome your issue.

Check it out here -> https://github.com/urbanairship/php-library/blob/master/sample.php



来源:https://stackoverflow.com/questions/10698608/urban-airship-send-push-to-1-specific-device-device-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!