Closed HyeonjuPark closed 7 years ago
Try to use the Firebase Notifications console
https://console.firebase.google.com/project/<your-project>/notification
To send one manually to be sure that the issue is not on the device
If you're using iOS, please take a look at #7 and #8. If you're at Android, make sure you've properly generated the google-services.json. Additionally, can you inform your send object format?
Notification sent from Firebase Notification console works well.
`var fcm_message = {
to: 'MESSAGE_TOKEN',
collapse_key: 'test message',
notification: {
title: 'Title of test push notification',
body: 'Body of test push notification'
},
data: {
key: 'test value',
another_key: 'test another key'
}
};
I'm using Android and this is the object that is almost not changed from the sample you gave. Is it okay to use "Firebase Cloud Messaging token" in "to" property?
@HyeonjuPark The MESSAGE_TOKEN must be the user device token, or a topic the device is already subscribed with a format like "/topics/YOURTOPIC".
To get this device token look at this firebase documentation page
EDIT: Typo, 'topic' -> 'topics'
Thanks a lot! Getting the user device token following the link, I got the notification. However, when I used topic like this
to: '/topic/test', //server
FirebaseMessaging.getInstance().subscribeToTopic("test"); //client
it didn't work. Seems something I'm wrong again. Is there a way to broadcast all users?
@HyeonjuPark sorry for the typo, the correct is plural -> /topics/YOURTOPIC
To broadcast a message to all users you can use the firebase console, or subscribe all your clients in a central topic defined by you.
I'm sorry to reply late. It works!! thanks I really appreciate for your kind response.
Glad it worked. Feel free to report any other issue.
@jlcvp My registration token is correct and notifications are sent by the server but didn't received by client app. What is the problem? I tried refreshing the token as well.
@Priyadarshanipp Can you give more information?
FirebaseInstanceId.getInstance().getToken()
method?module NotificationHelper require 'fcm' def send_notification(location, message,user_id ) firebase_key = Rails.application.secrets.firebase_key
user = User.find_by(id: user_id)
fcm = FCM.new(firebase_key)
registration_ids= [user.device_token] # an array of one or more client registration tokens
options = {:data => {message: message}, location: location}
response = fcm.send(registration_ids, options)
end end
Hi I am facing the same issue. I am also not able to get the notification on device This is my message object : let message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera) to:"Users device token", collapse_key: "your_collapse_key",
notification: {
title: "Title of your push notification",
body: "Body of your push notification"
},
data: {
//you can send only notification or only data(or include both)
my_key: "my value",
my_another_key: "my another value"
}
};
Successfully sent with response: {"multicast_id":5979505685602066267,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1479724040861830%0000000000000000"}]} I put my own server key and message token and client app is implemented with FirebaseMessagingService and FirebaseInstanceIDService. When I run the server, it returns success response like above message. However, client app doesn't get any notification. what am I missed?