I am using Google Cloud Messaging for my Android application and I am trying to understand when the registration id expires. From this post I was able to understand that Google tends to refresh the ID at some time. I am curious how my application will know when the id gets refreshed? If Google decides to refresh the ID and my server is till sending the message to the old ID I dont think the message will get sent. So would I have to try and register every time and see if the ids are same?
Also the same post says that the id would get refreshed when the app version changes, but on changing the version through the manifest the registration id did not change. So what is the point on trying to register again of the version changes?
EDIT Here is the server side. Where exactly would the canonical id be stored?
Server side code:
<?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;
?>