Notification tap redirection : Flutter - ios

I want to redirect to a specific page on remote push notification tap in my flutter app. So I fire the following JSON payload from the backend,
{
"to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF---------------------",
"notification": {
"title": "Krunal Here",
"body": "Test notification Krunal",
"product_id" : "124",
"content_available": true,
},
"data": {
"title": "Krunal Here",
"body": "Test notification Krunal",
"product_id" : "124",
"content_available": true,
},
"priority" : "high"
}
Notifion received on both Android and iOS devices. But I face 3 problems,
Android phone received 2 notifications, I think one local notification generate automatically because I used "notification" keyword in the payload.
(I removed "notification" object from the payload and pass only "data" it works fine in the android app but didn't receive any notification on the iOS device. So must have used "notification" keyword that I found, Event I tried to use "aps" keyword but iPhone did not receive any notification.)
iOS App redirection is not working because I didn't get product_id from the payload.
If I use both "notification" & "data" notifications received on both apps. (Android received 2 notifications as I mention above) But redirection is not working in any app.
What is the correct payload format for the flutter app? Can you please help me to find this solution?

Related

Firebase Notification Flutter iOS

I have developed a flutter application and integrated Firebase notification and firebase phone authentication.
I am able to do phone authentication both on development mode as well as after the app is published
I am able to receive notification when the app is development mode - but when I publish the app I dont receive the notification.
I should point out here that I am able to receive the notification if I send it from the firebase console (even after the app is published) - but I do not receive notification from my panel after the app is published (but the same is working absolutely fine otherwise)
I should also point out that this problem is only faced with iOS and not android.
What am I missing?
When you are sending notification to mobile phone using firebase push notification service then make sure the payload is set correctly in order to successfully deliver the notification to mobile phone.
The basic example of the payload for FCM is as follows.
{
"to": "<FCM TOKEN OF DEVICE>",
"data": {
"key1": "value1",
"key2": "value2"
},
"priority": "high",
"notification": {
"body": "This is body",
"title": "This is title",
"sound": "default"
},
"message": {
"notification": {
"title": "This is title",
"body": "This is body"
}
}
}
You can go through this article to know more about FCM service and its payload.
EDIT
Also you need to make sure that the correct certificate is uploaded on the firebase console.
You can export those certificate from the keychain.

Firebase Cloud Messaging Silent Push Notification fail to work

I have implemented firebase cloud messaging in my app and I wish to implement silent push notification.
I have done all the necessaries and send the following json post request to my app.
{
"to": "/topics/news",
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
},
"content_available": true,
"priority": "normal"
}
The app successfully receives the notification when it is in background, but the notification is still displayed as banner (I believe silent notification means there will not be any badge, banner displaying right?)
If you want your notifications to be silent, they have to contain only data payload, with no notification content. So, you should remove this:
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
}
Review message types for more details.

cordova, Firebase, FCM Plugin - Not showing notifications in notification bar on iOS

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

Firebase API is not sending push notifications when using the API

I'm migrating from Parse to Firebase and facing a problem with our ios app.
The Firebase API does not send push notifications to the ios app.
This is what im sending to https://fcm.googleapis.com/fcm/send
{
"to: "<registration token>",
"priority": "high",
"data": {
"customId": "<my custom id>",
"badge": 1,
"sound": "cheering.caf",
"alert": "New data is available"
}
}
And the server is returning success
{
"multicast_id":6917019914327105115,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1468961966677585%f0f84693f9fd7ecd"}]
}
But the push is not delivered.
If I sent the push using the Firebase Dashboard, the pushes are delivered, even if I targeting directly with the Token.
I saw another developer complaining in another Stackoverflow question
Can't send push notifications using the server API
I tried their solution of adding the "priority": "high", it did not fixed the issue. But it gave me a clue: They are also using the dev/sandbox push certificate.
My suspicion is that the Dashboard can use the ios Development certificate, but the API can not. The problem only happen on the ios device, since the android app are getting the pushes through API.
Is anyone able to send pushes using the API and the development certificate?
I got contacted by Firebase support and was able to find out what is wrong
My push payload was missing a notification object
{
"to": "<registration token>",
"priority": "high",
"notification": {
"title": "Your Title",
"text": "Your Text"
}
"data": {
"customId": "<my custom id>",
"badge": 1,
"sound": "cheering.caf",
"alert": "New data is available"
}
}
I hope that helps someone else
The object you send to https://fcm.googleapis.com/fcm/send with Firebase API should look like this :
{
"notification":{
"title":"Notification title", //Any value
"body":"Notification body", //Any value
"sound":"default", //If you want notification sound
"click_action":"<activity_name>", //Must be present for Android
"icon":"fcm_push_icon" //White icon Android resource
},
"data":{
"param1":"value1", //Any data to be retrieved in the notification callback
"param2":"value2"
},
"to":"/topics/topicExample", //Topic or single device
"priority":"high", //If not set, notification won't be delivered on completely closed iOS app
"restricted_package_name":"" //Optional. Set for application filtering
}
Please if your problem has been solved don't forget to mark it as such.

iOS not receiving Firebase Push Notification sent through the API

I'm using Google's Firebase Cloud Messaging to send push-notifications to my iOS and Android applications. The push-notifications sent through the Cloud Messaging console work just as intended, however when I send a push-notification through the API, the iOS application only receives it when in foreground. On Android, it is working correctly (both in foreground and background).
Reading the documentation, the iOS system would then transfer the "notification" object to the system tray, as intended, showing the "body" message. However, this is not working.
Here's the content of the JSON I'm sending:
{
"notification":
{
"body": "This a test notification"
},
"to":"eQ5tiy0cMZ8:APA91bE4CCjDXEJxEIRxKY18pXMMGUBqY1OKJFhVbR-pNhvQjJuhPcc7pXa..."
}
Did anyone have similar problems using Firebase Cloud Messaging recently? Thank you.
I managed to fix the problem thanks to this answer: https://stackoverflow.com/a/37550067/516338
Basically, although NOT in the documents, you have to set the "priority" field to "high" on iOS, like this:
{
"to": "cHPpZ_s14EA:APA91bG56znW...",
"priority": "high",
"notification" : {
"body" : "hello!",
"title": "afruz",
"sound": "default"
}
}

Resources