I am successfully sending GCM push notifications for my android users using PHP, but i want to set expiration date for my push notifications so in case the user has no internet connection for 1 week, it will not receive the old push notifications. How i can achieve it.
Thank you.
This is the php code:
private $GOOGLE_API_KEY = "XXXXX";
public function send($registration_id, $data) {
// include config
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registration_id,
'data' => $data,
);
$headers = array(
'Authorization: key=' . $this->GOOGLE_API_KEY,
'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);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
// echo $result;
}
there is a param
time_to_live
which you are setting while sending. value is in seconds (below one minute only)more here