Urban Airship - 将PUSH发送到1个特定设备(设备令牌)

时间:2012-05-22 08:44:17

标签: php ios push urbanairship.com devicetoken

所以我想通过Urban Airship定位一个特定的设备令牌,但无论我做什么,我的所有设备都会收到针对特定设备令牌的消息。

这是我的PHP代码 - 非常感谢任何帮助!

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);

2 个答案:

答案 0 :(得分:5)

您使用的网址是广播。要向特定设备发送通知,您应使用的网址为“https://go.urbanairship.com/api/push/”

答案 1 :(得分:1)

Urban Airship提供了示例PHP代码来克服您的问题。

在这里查看 - > https://github.com/urbanairship/php-library/blob/master/sample.php