And*_*v93 9 android google-cloud-messaging
我正在为我的Android应用程序使用Google Cloud Messaging,我正在尝试了解注册ID何时到期.从这篇文章中我可以理解谷歌有时会刷新ID.我很好奇我的应用程序将如何知道id何时刷新?如果谷歌决定刷新ID,我的服务器直到将消息发送到旧ID,我不认为该消息将被发送.那么我每次都要尝试注册并查看ID是否相同?
同样的帖子说,当应用版本更改时,id会刷新,但是在通过清单更改版本时,注册ID不会更改.那么试图再次注册版本更改有什么意义呢?
编辑 这是服务器端.规范ID存储在哪里?
服务器端代码:
<?php
// Message to be sent
$message = $_POST['message'];
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => array($_POST['registrationIDs']),
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $_POST['apiKey'],
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
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_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
?>
Run Code Online (Sandbox Code Playgroud)
我试图了解注册ID何时到期
GCM服务器通常刷新(因此您的旧注册ID已过期)注册ID.如果发生这种情况,则无法记录.但是当发生这种情况时,您会收到通知.
我们如何通知?
当您向已过期的注册ID发送通知时,将首次发送消息(通知),但您将获得一个名为canonical id的新注册ID.这意味着,您发送邮件的注册ID已更改为此规范ID,因此也请在服务器端更改它.
如果谷歌决定刷新ID,我的服务器直到将消息发送到旧ID,我不认为该消息将被发送
就像我说的那样,它将在第一次发送,即使在到期后也是如此.
同样的帖子说,当应用版本发生变化时,id会刷新
我认为这不会发生.但即使它发生(注册ID改变)它与上面解释的相同的场景,所以你需要的只是照顾规范的id.
编辑
$result = curl_exec($ch);
$result = json_decode($result);
$canonical_ids_count = $result->canonical_ids;
if($canonical_ids_count){
//update your DB by replacing the registration id with
//the canonical id(new registration id)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12000 次 |
| 最近记录: |