I am able to successfully send from Firebase push notifications and receive them on mobile. I can do everything (so far) using the official firebase_messaging package.
In my Flutter app there's a variable called bool isAdmin which can be true or false, it depends. I need to make it so that some notifications are seen only by people that are actually admins.
In other words, certain push notifications can be seen only if isAdmin = true. How can I do this?
POSSIBLE SOLUTION
I am thinking to add a flag in the body payload of the push notification called adminPush which can be true or false. But then, how can I read this field and prevent the notification to appear?
According to this the notification block of the push notification gets displayed by the push notifications SDK itself if the app is backgrounded, so one way to fix this is sending only data block, omitting notification block altogether for this particular push notification type, and displaying a local notification if isAdmin = true.
Related
I am currently using Airnotifier and Firebase Cloud Messaging. From some other questions and after trying by myself, it seems Firebase does not support actionable notifications. Is there a way to create one somehow, or can we somehow send a request to the user's device and the application on that device can create an actionable local notification?
UPDATE: Just checked with the FCM API and SDK, title and body fields are accepted but actions and click_action are not seen anywhere. Is there a way to verify if those data have been given or if those are the correct name for the fields?
UPDATE2: gcm.notification.actions has shown in the notification received in iOS, but not click_action which I included in the notification field.
UPDATE3: It seems the "actions" field magically disappears after the "schedule" function is called in ionic's local notification plug in.
I would just like to receive the notification data via the OnMessageReceived method and then display a custom notification with Unity's MobileNotification or UTNotification.
Any information in the notification property of a message is automatically handled by the system when the app is not active. If you don't want the system to automatically display a notification, make sure that your message contains no notification property. Data only messages are not displayed by the system automatically.
For more on this, also see the Firebase documentation on message types.
While it is possible to add data properties to an FCM message that is sent through the Firebase console in the Custom data section of the Additional options, there is no way to send a data only message. Messages sent through the Firebase console will always have a notification property, which is what triggers the system to display them.
If you want to send data-only messages, the simplest way is through a CURL command as shown here: How can I send a Firebase Cloud Messaging notification without use the Firebase Console?
Thanks to Firebase and FlutterFire, it's easy to send regular notifications from the servers to the users' devices. Those notifications include a title, a body, and an image url. But what about creating a no-that-simple notification, like Telegram's or WhatsApp's?
The simple question is to avoid sending a Notification from the server, and instead set the data field to the push message. But according to the FlutterFire documentation:
Data only messages are considered low priority by devices when your application is in the background or terminated, and will be ignored
So, it sounds like if we want to have a reliable delivery system, we should add a Notification to our push messages. But that notification is so simple. And, again, according to the documentation:
If your message is a notification one (includes a notification property), the Firebase SDKs will intercept this and display a visible notification to your users (assuming you have requested permission & the user has notifications enabled)
So: If I want a reliable system, I have to send Notifications, but I do it, I can't tell FlutterFire to use my custom notifications.
So the question is: how to show custom notifications with FlutterFire?
What I want to achieve is something like this:
I'm going to try setting the priority of the push notification.
You can however explicitly increase the priority by sending additional properties on the FCM payload:
On Android, set the priority field to high.
On Apple (iOS & macOS), set the content-available field to true.
On the server side code, it looks like:
message.setAndroidConfig(AndroidConfig.builder().setPriority(AndroidConfig.Priority.HIGH).build());
message.setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setContentAvailable(true).build()).build());
I am working with Firebase to push notifications and I don't use Firebase authentication on my app (I have my own system).
I didn't find an answer to this question:
Is it possible to push notifications to a specific user with firebase without Firebase authentication (and therefore, without a UID)? How?
The push notifications are not sent based on user, they are sent based on push notification token that is received when you register for push notifications (iOS & Android).
The push notification token will change in the case of uninstall/install and has nothing to do with what user is logged in in the app, you can send push notifications to apps that don't have users at all.
In order to target a specific user with push notification, you must do something called user segmentation, that is, filter user based on particular properties of these users. In general user segmentation is done by tracking user action and user properties and depends on the push notification platform in use. For example you can track user actions in the app, like user added product to cart, user has x products in cart and then send a push notification to all users that have more than 3 products in cart.
All the push notifications platform link the push notification token to the events triggered.
If you are using firebase, the most easiest way is to track user properties, there are a lot of tutorials on this part. Although, in my opinion, firebase tracking is kind of crappy.
One thing to note, since the push notification token is not linked to the user directly, in case there are two users (two accounts) using the same device they, they will receive push notifications on the same device, so don't send sensitive information via push notifications.
I am using Firebase Push notification its works fine but i have a question what if,
I need the ability to provide parameters to the Firebase push
messaging system that will allow me to display a message that, when
clicked, goes to a specified web link - in a web view. Most
importantly, this needs to function when the user does not have the
app loaded.
Is it possible ?? I gone through the documentation of firebase but didn't get anything about it.
For sending notifications to a user when they might not have the app running, use Firebase Cloud Messaging.
For sending messages to a user when they might not have the app installed, use Firebase Dynamic Links or Invites.
May be you have to try "Advance options" under the pushnotification by sending the key value pair like following(link is parameter and you set this parameter value in firebase console):
window.FirebasePlugin.onNotificationOpen ((notification) {
if notification.link != '' && notification.tap == true
ref = cordova.InAppBrowser.open(notification.link, '_blank', 'location=yes')
window.open = cordova.InAppBrowser.open
}