My question is about the APNS push notification data structure that is used behind the scenes for Firebase when triggering a push notification. Specifically, it's about the deep link that Firebase uses for its dynamic URLs that opens an application in a specific view.
The structure of the dynamic URL looks something like https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]
. My understanding is that Firebase must eventually send an APNS push that goes to the receiving iOS application in the end. Somewhere in the sent data structure there must be the information contained in this URL.
The default APNS data structure looks something like:
{
"aps": {
"alert": {
"body": "My message"
},
"badge": 1,
"sound": "default"
}
}
Where in this structure does the Firebase dynamic link information go?
According to APN docs it must be as peer to "aps" key.
Related
I use nativescript-vue and this plugin for sending push notifications:
nativescript-plugin-firebase,
How do i send an image along when i send a push notification?
In my nativescript-vue project i receive the notification like this:
firebase.init({
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: async (message) => {
})
How do i show an image in the notification?
I have tried with including image: "url" and that dosnt work. I think there is way to show a image in the notification because on the firebase panel there is an option to send along a image.
The firebase notification plugin only acts as a receiver and handler of notifications in this case. If you want to send a remote notification with image, you are going to do that with your notification sender; and in this case on Firebase.
If you just want to quickly send or test a push notification with an image, you can do so by going to Firebase Console > Cloud Messaging.
Then just add your image in the respective field.
Now, in most cases in production you would want to do this progmatically on your backend instead of going to Firebase Console. You can do that by using Firebase FCM SDK.
In our case, we usually do it via API calls something like:
POST https://fcm.googleapis.com/fcm/send
BODY
{
"to": "/topics/user_{{userId}}",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
Header should include a key "Authorization" with value:
key=<YOUR_FCM_KEY_HERE>
You can get your FCM key by going to Firebase Console > Project Settings (the gear) > Cloud Messaging. You can check this doc for more details on sending.
Lastly, if you really want to handle the notification image via your app (not suggested), you can force so by using a local push notification by force handling the remote push notification and doing a local push notification with your own desired image.
So I have registration/login handled on my side using Laravel. I tried adding React-native-firebase so after login I could subscribe to topic like notifications/:userId so I would get notifications only for that user as currently every user is getting push notifications.
I can't find any guide on how to make this so it will work when app is in "dead" state or minimized.
I'd appreciate any help.
Thanks
You can use the below mentioned library for firebase integration.
https://rnfirebase.io/
Firebase has the Firebase Cloud Messenger, which has some notification control and badges from notifications built into it. I hope that helps, here is a link React-Native (https://rnfirebase.io/docs/v3.1.x/messaging/reference/messaging) and Firebase Docs (https://firebase.google.com/docs/reference/js/firebase.messaging)
You have generate fcmtoken after user log in, and save it to database.
After that from server side you have to fetch the fcmtoken for that particular user and call firebase pushnotification api / service.
Notification Payload :
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}
If you want to send message/notification to multiple devices minor change is
tokens: ["token1", "token2"]
I'm using Xamarin and Firebase Cloud Messaging to send push notifications to mobile devices.
I have notification settings where the user can allow and block specific notification types. So I made topics A, B, C for example. If the user allows notifications of type A, then the device will subscribe to topic A. I want to send a unique notification to that device if it is subscribed to notifications of type A. However, it seems that I cannot add two parameters to 'to: '
Currently I have:
{
"to": "{device_token}",
"data": {
"message": "hello",
},
"priority": "high"
}
I tried to add "condition": 'A' in topics but it doesn't allow me to have both 'to' and 'condition'.
You can't combine topics and tokens in the way you're trying. If you send a message to a topic, the message is delivered to every instance that is subscribed to that topic. If you send a message to a device token, it is only delivered to that device.
Some options I can think of:
Send a data message, and then detect in the client whether to show it or not.
Build your own message targeting system on top of device instance IDs.
I had read that not to add notification node in the body of the request, and I tried to send without notification node but it seems that the message not received but when I add the notification node it work well
So, what is the difference notification node and data node in Firebase cloud messaging?
{
"to": "/topics/some_topic",
"data": {
"key_1" : "some_value",
"key_2" : "some_value"
},
"notification":{
"body" : "some_message"
}
}
Is there any link to doc I can read ?
The data node is used for sending notification if the application is on the background/foreground and in some phones if it is also killed.
The notification node is used for sending notification if the application is on the foreground. If it is in the background you wont receive the notification.
The best option I found is to use data node alone.
Also it is explained very well in this link: The FCM messages types
Notification node (a.k.a Notification messages)
When sent, this will receive a notification on the device, regardless of whether the app is in foreground/background/terminated state, but the notification will be shown only when the app is not in foreground. You can bundle a data payload with this of upto 4 KB. The upside is that you do not have to worry about generating a notification every time, the libraries take care of that. The downside is that there is no way not to show the notifications, for eg when you want to do something silently.
Data node (a.k.a Data messages)
When sent, this will fire up all the same callbacks as a normal notification node would, the only difference being that a notification won't pop up on its own, you are the master of your own callback! This is useful for when you want to do something silently, like refresh the cache, update the database etc. As a data node will have the data payload and will fire up a callback at any state of the app, you can generate a notification on your own and fire it up. This gives you the freedom to design your notification however you want!
I've been trying to debug Firebase push notifications for quite a long time now, and got no luck. I believe I have set up provisional profiles and APNs certificate correctly. When I do not include the method
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .unknown)}
App receives notifications in foreground when sent from Firebase Notification console because it gets printed out, but it does not receive notification in background.
If I add the above method to it, it does not receive notification in foreground and background.
Anyone knows what is wrong?
I have already enabled push notifications, remote notifications, and I have setup the APNs certificate correctly. I have also tried reinstalling the app but it does not work. I have also tried all the stackoverflow posts already regarding this issue.
The code snippet that you've provided is for manual mapping of APNS token with the device registration token. Basically, you need to explicitly add this when the swizzling is disabled for your app.
Make sure to use the right token type: FIRInstanceIDAPNSTokenTypeSandbox for the sandbox environment, or FIRInstanceIDAPNSTokenTypeProd for the production environment. If you don't set the correct type, messages are not delivered to your app.
In addition, make sure that the priority is set to High in the Advanced options section when creating a new message in the Firebase Notification console.
If you're using a data message type to send notification to the client apps via FCM, then it is an intended behavior.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
}
Per the Firebase documentation:
On iOS, FCM stores the message and delivers it only when the app is in the foreground and has established a FCM connection.