I use cordova-plugin-fcm plugin for send notification for my IONIC App. I need to send image in notification in my application, So I use notificationOptions in my PHP code.
Without the notificationOptions notification show in my Device tray, but when I try to implement notificationOptions in my PHP code, then Notification not show in my Device tray but I get in my console log:
{"notificationOptions":"{\"largeIcon\":\"https:\\/\\/avatars2.githubusercontent.com\\/u\\/1174345?v=3&s=96\",
\"smallIcon\":\"mipmap\\/icon\",
\"id\":4,\"text\":\"Test message\",
\"title\":\"Title test\",
\"autoCancel\":true}",
"dataValuesToGetWhenClickedOn":"111","wasTapped":false}
PHP Code:
`<?php
$msg = array
(
"dataValuesToGetWhenClickedOn" => 111,
'notificationOptions' => array(
'title' => "Title test",
'id' => 4,
'text' => "Test message",
'smallIcon' => "mipmap/icon",
'largeIcon' => "https://avatars2.githubusercontent.com/u/1174345?v=3&s=96",
'autoCancel' => true
)
);
//print_r($msg); // exit();
$fields = array
(
'to' => "c5clRYgB1vo:APA91bGTlyTQur2S9b5iksc16-T0KzwV9Ein0n0RSafgDBdgxVKjhGQU0BLPmvnJVShCKDhlpeJCpHthmRglQcegT",
'data' => $msg
);
$data = json_encode($fields);
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Accept: application/json','Content-Type: application/json',
"Authorization: key=---Api Key---");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//curl_exec($ch);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
}
?>`
Please help me. I want to know that what I am doing wrong.
It solves my problem. If any one face same problem,
Please follow the link:
https://github.com/andrehtissot/cordova-plugin-firebase-extended-notification-app-example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.