We have a Django backend server using pyfcm to deliver Notifications throgh Firebase Cloud Messaging (FCM). I just updated to the today released Version 1.3.0. I want to send a notification using the loc-key and loc-args parameters so it can be displayed in the language the user is using on his phone. The notification reaches the device, it vibrates and makes the default sound for a new notification, but it will not displayed. It just happens nothing except for the sound and vibration.
This is the payload generated by the server which is sent to the fcm endpoint:
{
"notification": {
"loc-args": ["Demo (#demo)"],
"loc-key": "notification-follow",
"sound": "Default"
},
"priority": "high",
"to": "..."
}
On the client side, this is what is received by the phone:
[
AnyHashable("gcm.message_id"):0:1496257581534217 %f910cc44f910cc44,
AnyHashable("aps"):{
category = profile;
sound = Default;
},
AnyHashable("gcm.notification.alert"):{
"title-loc-key":" notification-follow",
"title-loc-args":[
"Demo (#demo)"
]
}
]
Is there anything I have to do before the message is displaying? Sending the message without the loc-key and loc-args but with message-body presents the notificaion on the device. Maybe the payload is wrong? How should it look like to do what I want?
The key, notification-follow in this case, is listed and translated in the Localizable.strings files in any available language.
Ok, problem solved. It was pyFCM. I thought it would be an error with this library, so the developer pseudo-fixed it. But it worked properly, and now it doesn't work anymore. The trick is to give body_loc_args an array, otherwise it will give you an InvalidParameters error.
Related
So I'm using the firebase push notification in my app. Notification is working fine with the following payload,
{
"to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF1cllsEV3l------------",
"notification": {
"title": "10-inch Aggretsuko Rage #24 (Jumbo Size)",
"subtitle": "Test notification Krunal"
}
}
But when I used the same payload format that mentions in the apple documentation then the notification is sent successfully but not received on the device. Check this payload,
{
"to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF1cllsEV3l------------",
"aps" : {
"alert" : {
"title" : "10-inch Aggretsuko Rage #24 (Jumbo Size)",
"subtitle" : "Test notification Krunal",
},
"category" : "GAME_INVITATION"
},
"gameID" : "12345678"
}
Can someone please explain what's the actual problem with the above payload I want to use that in my flutter app. When I used the notification keyword in the payload that create a problem in the flutter android app. Can someone please help me to solve this problem?
What is happening here is that you're using FCM messages. When you do this, you actually send the notification payload to Firebase. Firebase then transforms this payload into the appropriate payload format for iOS or Android or web and then sends it to the respective messaging service.
For the payload that you've built looking at the Apple documentation to work you would have to send it to APNS.
You can specify Apple specific keys in your FCM message as-well. See the documentation here.
You can use the ApnsConfig object to specify things that are specific to Apple devices.
To set options specific to Android devices you may use the AndroidConfig object.
Now, coming to the problem you mention with the Android app, looking at the 'to' field in your payload, I must assume you are using one of the legacy APIs (XMPP Server Protocol or Legacy HTTP Server Protocol) instead of the ones I have suggested above. In this case, are you sure you have updated the recipient in the 'to' field when sending the payload? If yes, then could you please explain the problem you are seeing in your Android app when using the FCM specific payload.
I think the problem is that Firebase wants a different JSON structure than the proprietary data structure that actually ends up being used on Apple systems. Firebase is doing the conversion for you from your first example.
Your second example is the kind of payload the Apple Simulator can make use of xcrun simctl push so it is still helpful for local testing and development.
The final part of your question about why it is a problem for Android I am not sure about. But I wonder whether you supplied the wrong FCM token because that might encode the intended platform type within in making it incompatible for Android delivery. Firebase seems to always know the right platform specific way to deliver a push message, whether it is Android or iOS, so it must keep a track of that via the FCM token.
Hello I'm stuck and I need help.
I have an iOS application build with Angular2 + Cordova + cordova-firebase-plugin + xcode.
I have setup the app on developers.apple.com and firebase.console website.
Now when I try to send a Notification message, I don't receive it on Iphone at all.
If the application is runing in the foreground, I see in the debug console that the notification was received, but it is not displayed on the Iphone.
Message from console:
Received data message: {
"collapse_key" = "com.example.app"
from = 793840040300;
notification = {
body = "example test notification message";
e = 1;
}
}
What I don't see here: notification title. (The notifications are working in Android, but not in iOS).
There were no any prompts about enabling the notifications (permissions prompt).
I trieed to setup APNS-FCM connectivity via .p12 Certificates and via .p8 Certificates (via the key). Boths atemmpts did not give me positive result...
One more moment:
IF the application is running in the background - I don't see the message in the console until I will open the app. When I open the app, the message appears in the console, if it was sent while the app was in foreground..
I viewed many different guides, but I didn't get any result.
I read that emulators does not support the push notifications, so I connected a real device via USB. And it behaves the same - no push notification received - only the message in the console.
Please, help me.
Make sure you are sending both the title and body in the payload. I had the issue (in Android) that when not sending the message item, the notification would not show up in the notifications bar. The same applies for iOS, but in this case, the variables are title and body.
If the right variables are not found in the payload, both Android, iOS and Windows Phone will consider it a background notification that is silently delivered to the app (once it's opened). Notifications will not wake an unloaded app, the app is launched by the notification item once it's selected from the notifications bar in this case.
Try sending the default payload from the documentation to test it:
{
"aps": {
"alert": { // alternatively just a string: "Your Message",
"title": "A short string describing the purpose of the notification",
"body": "The text of the alert message",
// localization of message is possible
"launch-image": "The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider"
},
"badge": 5, // Number to show at App icon
"content-available": "0", // configure background updates, see below
"category": "identifier", // Provide this key with a string value that represents the notification’s type
"thread-id": "id", // Provide this key with a string value that represents the app-specific identifier for grouping notifications
"sound": "default" // play default sound, or custom sound, see [iOS Sound](#sound-1) section
},
"custom_key1": "value1",
"custom_key2": "value2"
}
If this doesn't work, please include the entire content of the payload you are sending to APNS, from the server side.
Edit: make sure you are sending your payload fields in UTF-8 encoding to all push services.
I'm using this plugin with cordova: cordova-plugin-fcm to get notifications working.
It works good on Android.
Problem is with iOS, when the app is in foreground the notifications arrives. But when the app is closed or in background, the notification doesn't show in notification bar, but when I open the application I can see the notification arriving and the popup I generate, gets opened.
But I really need to notification to show in lock screen and in the notification bar.
This is what I'm sending to Firebase API:
/ POST to https://fcm.googleapis.com/fcm/send
And in the body I'm sending this:
{
"to" : <USER_TOKEN>,
"alert":"Test",
"notification": {
"alert":"Test test",
"title": "Notification test",
"text": "Testing notification text"
},
"priority": 10,
"content_available": true
}
I've also tried with "priority": "high" and get the same results.
The notification arrives, but it only shows when I open the app. I don't even get it in the notification bar or lock screen.
Also I tried adding the "aps" property in the body, with all the information inside.. doesn't work.
I hope someone can throw some light into this..
PS: iOS v10.1.1
PS2: Works good on all android devices.
I've already read some answers from the community but doesn't seem to work:
Firebase API is not sending push notifications when using the API
iOS not receiving Firebase Push Notification sent through the API
Thanks for your time.
have you Upload your Development APNs certificate on console.firebase.google.com,
Upload your APNs certificate to Firebase. If you don't already have an APNs certificate, see Provisioning APNs SSL Certificates.
Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab.
Select the Upload Certificate button for your development certificate, your production certificate, or both. At least one is required.
For each certificate, select the .p12 file, and provide the password, if any. Make sure the bundle ID for this certificate matches the bundle ID of your app. Select Save.
you can refer link https://firebase.google.com/docs/cloud-messaging/ios/client
I had the same problem,
First of all, you need to use "body" instead of "text";
For priority you should always use "high" or "normal", for pushnotifications the default value should be high.
If you forget to use the "title" and "body" key in the notification object of your Json string, iOS wont add the notification to the notificatios list apparently.
If you want some custom values, then add a data object with custom values. like this:
"data":{
"data1":"value1",
"data2":"value2"
}
So try something like this:
{
"to" : <USER_TOKEN>, //or /topics/<topicname> or /topics/all"
"notification": {
"title": "Notification test",
"body": "Testing notification text"
},
"priority": high,
"sound":"default", //not using this one wont make your iOS device use sound
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
}
Combined with data object:
{
"to" : <USER_TOKEN>, //or /topics/<topicname> or /topics/all"
"notification": {
"title": "Notification test",
"body": "Testing notification text"
},
"data":{
"data1":"value1",
"data2":"value2"
},
"priority": high,
"sound":"default", //not using this one wont make your iOS device use sound
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
}
I hope this helps, it did for me
I have an app running on iOS 9.3.5. I need to be able to send a push notification to my app when it's in the foreground or background. I don't actually need to include any data, I just need to ping the app so it will "phone home". So I don't need/want the user to see any notifications.
Since the company is already using Firebase for their Android app, I've set that up in the iOS app. If I send a message to https://fcm.googleapis.com/fcm/send with the notification key in the payload, it's received on the iPhone. When I try it with the data key instead, I get nothing. In both cases I get a success response from the POST. I've implemented the follow callbacks:
application:didReceiveRemoteNotification:
userNotificationCenter:willPresentNotification:withCompletionHandler:
applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage
None of those are called when sending a message with the data key.
Edit:
This is the payload I'm using.
{ "data": {
"message": "phonehome",
},
"to" : "xxxxx"
}
After doing some more testing it looks like I get that message when the app is in the foreground but not the background. When I switch to the foreground then application:didReceiveRemoteNotification: gets called.
Edit 2: Added content_available and that did the trick. Thanks!
{ "to" : "xxxx", "content_available" : true }
It's a little bit hard to suggest without a sample payload, However, do try to use the priority parameter as high or content_available to true.
I am currently working on an app and I have implement firebase Push Notification service into my app. I am recieving notification on my iphone but I am unable to set the custom alert sound that I want.
I added the sound as a .caf
I added the sound to the Copy Bundle Resources
using print (userInfo) I have collected this data that is incomming from Firebase
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
I understand where the problem is, I just dont understand how to fix it so that the app plays my custom notification sound.
Problem with Firebase is that you can not send sound parameter like custom parameter with Firebase Console, if you try this as you do, you will get this parameter in app outside of aps Dictionary and the system will not recognize it as a sound to be played although the sound file is into the project.
The only solution for this problem is you have some API/server through which you'll be sent a Firebase notification. When server send you a notification with sound param it will be within aps Dictionary and application will play this sound when the notification arrives.
After much research I have not found any solution.
Under Firebase Messaging Docs, and
Table 2a. iOS — keys for notification messages
it is indicated that Firebase does allow for the Sound key to be included in the payload but as seen in the code printed by didRecieveRemoteNotification,
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
Firebase doesn't include the Sound key inside the aps hence not calling the sound key by the app.
The workaround that I used for my app is Easy APNs Provider which is a handy and easy app to use for development purposes, a major issue is that it doesn't have the ability to register and remove notifications automatically.
lastly: for Push Notifications to my published apps, I have opted for a dedicated server which I run off of my website
It's been over 5 years, but if someone still looking for an answer, here is what I did.
Make sure you have configured Firebase Messaging & receiving Notifications.
Add .caf ( sound file ) to the app. It must be visible on
'Target' - > 'Build Phases' & then under 'Copy Bundle Resources'
Delete the app from the device ( This is important )
I use Postman as my server, so message format would be,
{
"notification": {
"title": "Hello",
"sound":"small_message.caf",
"body": "You have a new Job"
},
"to": "your device token"
}