I created some PHP code that gets a GCM register from the database and sends a push to an Android device. This code works ok, but when the user deletes the app on Android for example the GCM register in the database gets invalid. How do I know when the GCM register is invalid in order to delete it from the database using PHP?
This is the code that sends push:
//Getting api key
$api_key = "....";
//Getting registration token we have to make it as array
$reg_token = array($token);
//Getting the message
$message = $versiculo;
//Creating a message array
$msg = array
(
'message' => $message,
'title' => $capitulo,
'id_versiculo' => $id,
);
//Creating a new array fileds and adding the msg array and registration token array here
$fields = array
(
'registration_ids' => $reg_token,
'data' => $msg
);
//Adding the api key in one more array header
$headers = array
(
'Authorization: key=' . $api_key,
'Content-Type: application/json'
);
//Using curl to perform http request
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
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 ) );
//Getting the result
$result = curl_exec($ch );
curl_close( $ch );