Hi,
I’ve been testing my app on an iPad and a Huawei smartphone (Android).
I use the plugin Push from @ionic/cloud-angular to send notifications when a new article is published on our website.
For some reason, when I use the https://apps.ionic.io Push form, both of my devices receive the notifications. But when I use the Ionic API with a PHP script on my website, only the iPad receive the notification. I have no idea why, maybe something is wrong in my PHP script ?
$apiurl = 'https://api.ionic.io/push/notifications';
$last_post = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER BY post_date DESC")[0];
$post_title = $last_post->post_title;
$post_type = $last_post->post_type;
$post_id = $last_post->ID;
$data = array(
'tokens' => $tokens,
'profile' => 'development',
'notification' => array(
'title' => $post_title,
'message' => $post_title,
"payload" => array(
"type" => $post_type,
"id" => $post_id
),
'ios' => array(
'sound' => 'default',
"content_available" => 1
),
'android' => array(
'sound' => 'default',
'image' => 'www/img/icon.png',
"content_available" => 1
)
)
);
$method = "POST";
$content = send_ionic_api( $apiurl, $method, $data );
function send_ionic_api( $apiurl, $method, $data ){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $apiurl);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: application/json', 'Authorization: Bearer MY_API_KEY'));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $data ));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
I’ve checked :
- the tokens (they’re valid),
- the notifications (they’re marked as “sent”, no error, for both devices)
- the phone (notifications are activated and there is an Internet connexion)
I don’t know what to do next.
Thanks in advance for your help.