I have a problem that I have not been able to solve. I currently work with ionic and vue to make an android app. The problem appear when I want to send a push notification through a curl request when the device is not connected to network (offline). If I send a single notification is no problem but when I send more than one is always overwritten and only the last one arrives to the mobile.
When the mobile is connected to the internet, all notifications arrive without problems.
I tried to setting the time_to_live parameter but apparently doesn't make difference.
Here is the code:
function sendNotification($i){
$apiKey = "API_KEY";
$tokens = ["CLIENT_TOKEN"];
$data = array(
"registration_ids" => $tokens,
"notification" => array(
"title" => "title ".$i,
"body" => "content ".$i,
"color" => "#33DDFF",
"priority" => "high",
"collapse_key" => 123
),
);
$headers = array(
"Authorization: key=".$apiKey ,
"Content-Type: application/json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , "https://fcm.googleapis.com/fcm/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($data) );
$result = curl_exec($ch);
curl_close($ch);
}
for($i=11;$i<16;$i++){
sendNotification($i);
}