Closed diego-amplya closed 7 years ago
If you are seeing a successful response like the one in the image you posted, that is a success message from APNS which lets you know it was able to send to the device token you provided, which would mean you set up the registration part of the app fine.
Can you post the notification you are trying to send?
I think you may be missing a key field if the notification is able to be delivered but not appearing on the device.
Thanks @DaDanny for your response! The notification I'm trying to send following the structure below:
$fields =
array(
'to' => muN23JAnlSY:..........................
'data' => {"data":{"title":"Test Notification","is_background":false,"message":"Hello","image":"","payload":{"team":"Spain","score":"7.2"},"timestamp":"2017-09-29 10:02:54"}},
);
Rest of data (curl):
require_once __DIR__ . '/config.php';
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY, //in config.php file
'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);
return $result;
@diego-amplya when sending to an iOS device using FCM/GCM to receive push information use notification
and not data
. For example:
$fields =
array(
'to' => muN23JAnlSY:..........................
'data' => {"notification":{"title":"Test Notification","is_background":false,"message":"Hello","image":"","payload":{"team":"Spain","score":"7.2"},"timestamp":"2017-09-29 10:02:54"}},
);
Thank you @macdonst for your response. I changed it but still doesn't work.
@diego-amplya what does your registrationId
look like?
It looks like you are using FCM for iOS notifications, which I am not using, so you may need to set some additional fields that I am not using, but for my notification server, I need to set a topic field which is separate from the payload object. If I do not set the topic field, my message will be delivered but will not display.
For example, my server uses node-apns to send notifications and my apn notification object looks like:
{
alert: {
title : 'Notification title',
body : 'notification message'
},
sound: "chime.caf",
payload: {
"sender": "node-apn",
notificationData : (I include additional data for the notification)
notId : (generated by my server)
},
topic : '<your app bundle id>,
expiry : Math.floor(Date.now() / 1000) + 259200,
collapseId : notification.collapseId,
notId : notId,
priority : 5,
contentAvailable : 1
}
So while that may not be the exact same object you need to send to APNS, it is an example of the fields I include in order for the notification to display and function properly.
@macdonst Like this
eXHhO7ZcNHs:APA91bE--DjFuuuOnsqhLO2sZ9wLMS........................................................
@diego-amplya that looks valid. Generally, when folks are getting the registration ID but not the push message on iOS it is due to a mismatch in the app and server. You have to make sure if you are registering to the development server that you send your push to the APNS development server, i.e. sandbox, as well.
Hi @macdonst ,
I've been doing several changes:
I uploaded the .p8 file to Firebase console
I changed the setupPush function in index.js
"ios": { "sound": true, "vibration": true, "badge": true, "senderID": "MY_SENDER_ID", "gcmSandbox": false },
At this point, I also tried "fcmSandbox": false, but I realized that gcmSandbox parameter only use when the version is 2.0.0 or greater.
The configuration in the server is as following:
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_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);
return $result;
$fields contains:
$fields = array( 'to' => lEulfXaHRc4:.......................... 'data' => {"notification":{"title":"Test Notification","message":"Hello"}} );
And still return the same message I posted on the first post.
I'm testing the application on TestFlight in an iPhone, I don't know if this would affect.
@diego-amplya If you are using 1.x the parameter is gcmSandbox
, for 2.x the parameter is fcmSandbox
.
Solved!
I've been re-create the .p8 files and upload to firebase console and doing some changes on my notification server.
Thanks for all, @macdonst @DaDanny
This thread has been automatically locked.
Expected Behaviour
Show notifications on iOS
Actual Behaviour
Not showing
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
iOS 10.3.3
Cordova CLI version and cordova platform version
Plugin version
Sample Code that illustrates the problem
I've sent the notification through PHP simple form and seems everything gone well.
Logs taken while reproducing problem
See the image, but the notifications does not arrive.