我已經在我的Android應用程序中實施推送通知。當重新安裝應用程序witouth註銷時GCM和規範ID
現在,我遇到了canonicals id的着名問題。 如果我在沒有註銷的情況下卸載應用程序,那麼在不刪除我的數據庫中的device_ids
的情況下,當我重新安裝應用程序時,我收到的不是新用戶的通知。
谷歌建議使用這個問題的規範ID,但我不明白我必須攔截它,並改變我的數據庫中的ID。 我有發送通知此PHP頁面:
$gcm=new GCM();
//get the array of all id associated to the user
$row= (query to get registration_ids from my database);
while($row = mysql_fetch_assoc($result)){
array_push($registration_ids, $row['id_device']);
}
//create a message to send
$mymessage="my message";
$message=array("message"=>$mymessage);
//send the notification and take the result
$result_android=$gcm->send_notification($registration_ids,$message);
echo $result_android;
//class that send the notification
class GCM{
function __construct(){}
public function send_notification($registatoin_ids,$message){
// GOOGLE API KEY
define("GOOGLE_API_KEY","xxxxxxxxxxxxxxxxx");
$url="https://android.googleapis.com/gcm/send";
$fields=array(
"registration_ids"=>$registatoin_ids,
"data"=>$message,
);
var_dump($fields);
$headers=array(
"Authorization: key=".GOOGLE_API_KEY,
"Content-Type: application/json"
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
$result=curl_exec($ch);
if($result===FALSE){
die("Curl failed: ".curl_error($ch));
}
curl_close($ch);
echo $result;
}
我應該在哪裏拿canonical_ids
和我的數據庫插入?服務器端還是客戶端?我很困惑。
在你的代碼中加入一些註釋可以幫助他人回答你的問題。讓標題更多的問題也會有所幫助。 – cmbarbu 2015-04-03 11:46:40
對不起,我編輯了我的問題 – diegocom 2015-04-03 11:56:13
看看SO貼子的答案,可能與你正在查找的東西有關,很多信息包裝在這裏。 http://stackoverflow.com/questions/27072824/how-to-get-canonical-id-from-gcm希望幫助! – AniV 2015-04-03 22:40:26