Closed antoinerousseau closed 7 years ago
My bad, I had a typo in the code so the priority wasn't set (in my case it must be set...)
@antoinerousseau Hi i didnt get notification on my ios device. please help me out
const FCM = require('fcm-node');
const apiKey = "MY API KEY" /// it replaced with my own values
const fcm = new FCM(apiKey);
var message = {
to:" device Token", /// it replaced with my own value
priority: 'high',
data: {
title: "msguser_sender",
body: "msguser_sender",
text: " msgmessage",
}
};
fcm.send(message, function (err,response) {
//console.log(tokenn + "fetchig right" + message +msg.message)
if (err) {
console.log(err);
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response: ", response);
}
});
res.send('respond with a resource'); });
what do you get in the log? (response or error)
@antoinerousseau Successfully sent with response: {"multicast_id":8837314142145939068,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1510925424333357%4d35cc53f9fd7ecd"}]} but not received any notification . :(
well first of all it's not data
it's notification
you must set in the payload.
@antoinerousseau still not getting
@antoinerousseau thanks alot its working 👍
I'm now using the official firebase-admin package anyway:
const admin = require('firebase-admin')
const account = require('./serviceAccountCredentials.json')
const app = admin.initializeApp({
credential: admin.credential.cert(account),
})
const messaging = app.messaging()
messaging.sendToDevice(token, payload, options)
.then(response => console.log(response))
.catch(error => console.error(error))
See the doc: https://firebase.google.com/docs/cloud-messaging/admin/send-messages
@antoinerousseau not getting notification in ios but in android it's working fine
const FCM = require('fcm-node');
// Replace these with your own values.
const apiKey = <API Key>';
const deviceID = '<Device id>';
const fcm = new FCM(apiKey);
const message = {
to: deviceID,
notification : {
title: 'Sound Test',
message: 'Loaded res/raw',
priority: 'high',
soundname: 'default'
}
};
fcm.send(message, (err, response) => {
if (err) {
console.log(err);
console.log('Something has gone wrong!');
} else {
console.log('Successfully sent with response: ', response);
}
});
Successfully sent with response: {"multicast_id":5920736412909434312,"success": 1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1528721367502716%4cb d4c214cbd4c21"}]}
@enlivenaman use firebase-admin as explained in my previous comment.
thanks @antoinerousseau it's working :+1:
hello i got same issues
Check my code Here: define( 'API_ACCESS_KEY', '------' ); // API access key from Google API's Console //define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' ); $registrationIds = array('e8-l_jCfL6M:APA91bHiE1nVEYDSAdLnIPI-Z5-Wo4_Z6nKkG6YEX5gpW1P79vrClvkX5YZ3w6cw9WbQ5WzoO0qDCxZHWzr0SVnIL_IE0aeD1XVGA7dj2JHnyYhpGMaB-Rv1Db5sK3g3C-UDEFAvlHq4Sb3Vi7tz53nBAnZuQ9bX0w','fnSbi298T44:APA91bH_Sy-gX1yzxofSVwLqjPxiCMdIQ2TGoUuc0BjxZaJIzRXO-RamaGSd6V-qOOY1nKNK5JtYlcLnw-vry8KCuqpxCbrDLHLtb2skSa_G-6IPnazk_whNOsxl_QEv8L83cjuL2qwdclscvdO25Oanuv8DNxIbzw');
//$registrationIds = array('');
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg,
'priority'=>'high',
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$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 ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
I have installed my new app on my iPhone 5s using Xcode, and the FCM registration token is successfully given to me when I start the app. When I use this token in the Firebase console (console.firebase.google.com), it works! But when I send it with
fcm-node
, it doesn't :/ Note that my config is working for Android. This is my test code:And I get:
But nothing arrives on the phone! (I have tried with the app in the background as well as killed) Again, I do receive the ones sent through the Firebase console, so my setup is correct imo...