How to send notifications to specific device on Flutter/Firebase Cloud Messaging without using Firebase Cloud Messaging Console [duplicate] - flutter

This question already has answers here:
Send notification over device using FCM and Flutter
(1 answer)
How to send push Notification using FCM and Flutter(One to Another Device)?
(1 answer)
Flutter: How can i send push notification programmatically with fcm
(3 answers)
Closed 1 year ago.
I can send notifications to all devices via Firebase Cloud Messaging Console. I can receive them in my Flutter app. That's not a problem.
But I want to send notifications to specific devices. Not to all of them. And I want to send notifications in Flutter. I don't want to use Cloud Messaging Console for that because I have an Blog Application. In this application, when user follows X Person, X person needs to get a notification that "XYZ followed you!". Just like Instagram. How can i achieve that in Flutter/Firebase?
I don't have any server side application. I only have Flutter application and as Backend I use Firebase Firestore.

What's wrong with using cloud functions? Makes your life easier, and you have more abilities as a site admin.
There is a way to send messages over HTTP requests in your fluter app. But this means that you will be storing your messaging key in your code and shipping it, this is not advise, neither best practice.
Regardless of the method you decide to proceed with, you will also have to capturing the devices' FCM tokens somewhere in your FireStore database, because that is the address you want to push your notifications to.
Using cloud functions is advised, it has great documentation, and it's almost for free up to 2 million cloud function invocations per month, then it's around $0.4 for every 1 million function, do you realize what that means if you have 2 million notifications per month?

Related

How to force the flutter app to request new data from the server?

I have an app made in flutter that requests data from a rest api. Currently, every time the app starts, it requests new data from the server. It also does that every 5 minutes.
I would like to know if there is any way to tell all apps from the server to request new data.
The purpose of this system is to avoid polling every 5 minutes and have information in the app almost instantly.
One way that occurred to me is to send a push notification indicating that there is new data. But I don't know how to do this. There are examples for sending notifications using firebase, but I am not using that service.
I also thought about web sockets but I think it is very expensive to maintain an open connection between the app and the server.
Any hold will be eternally grateful
I recommend you to use Firebase Cloud Messaging & Firebase Functions:
Firebase Functions could expose an HTTP Event
https://firebase.google.com/docs/functions/http-events
This event can send a push notification to the App and then you could listen to request new data
https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/example/lib/main.dart

Custom Notification Depending on action

SWIFT 3 / Firebase
app like instagram/Facebook
Notifications
I am working on letting users know when another user e.g. liked their post, made a friend request etc.
I set up everything for cloud messaging with firebase and can send bulk messages at all my devices.
Now I want to introduce notifications which contain the current user, the user who did the action and what happened.
Unfortunately I did not find anything about this despite the general implementing of firebase cloud messaging.
My questions are:
1: Do i have to structure a database (e.g. .child("notifications").child(userId).... ?
2: How do I get the token from the stranger user I address with the notification?
3: How can I make the input variable?
I am happy about all kinds of help!

Real-time notifications with Firebase & Ionic

NOTE : Don't say it's possible duplicate of this, Read through.
Think of a simple TASK Management application which can have n number of users. Say User A can create a task & assign it to User B. I want to show a notification to User B.
I am using Firebase as BAAS and following code-snippet prints on console only when there is a task assigned to User B. To simplfy, Users collection in Firebase has a node called tasksAssignedToThisUser array and callback function will be watching tasksAssignedToThisUser location. Whenever a new task gets added to that array, callback function gets executed. Here is the code snippet:
var rootRef = firebase.database().ref();
rootRef.child('users').child(loggedInUserID).child('tasksAssignedToThisUser')
.on('child_added', function (newMessageSnapshot) {
console.log('Someone assigned a task to this user.');
console.log(newMessageSnapshot.val);
});
Everything works fine until here.
What I have understood by reading Firebase docs & other post's on SO about Push notifications or Firebase Cloud Messaging is:
Firebase Notifications lets users easily send messages to reengage and
retain users, foster app growth, and support marketing campaigns.
Before you can write client apps that use Firebase Cloud Messaging,
you must have an app server that meets the following criteria:
...
You'll need to decide which FCM connection server protocol(s) you want
to use to enable your app server to interact with FCM connection
servers. Note that if you want to use upstream messaging from your
client applications, you must use XMPP. For a more detailed discussion
of this, see Choosing an FCM Connection Server Protocol.
This is definitely not what I want and maintaining a server for sending push notifications makes sense when bulk messages needs to be pushed to large number of devices. So I didn't name my question as Real Time Push Notifications.
I see a function being executed, which meets my use-case and I just want app to display a notification to the user in his mobile system tray on that callback function execution.
I am using Ionic 1 for developing app, completely new to Firebase and Ionic too. If there is a simple serverless approach that Firebase itself provides which can suffice my requirement, then I would be more than happy to hear about it.

Send push notification to specific user?

I'm making an app where I want to be able to set a basic notification (title, message, fire date) and have been trying to figure out the best way to setup the notifications. I'm working with Swift 3 and Firebase 3.
I don't want to use local notifications because if the user is logged in on multiple devices I want it to push to all those devices.
Is there a way to do this with FCM where a user can set a notification to fire at a specific date and time and have it fire on all (iOS) devices logged in?
If FCM doesn't have this, is there another APK that does? I've looked at Batch briefly but I'm already using Firebase.
Thanks in advance!
If your main use case is to send a push notification to a single user for his multiple devices, I suggest you make use of Device Group Messaging on iOS. As per the docs, it is typically used for:
With device group messaging, app servers can send a single message to multiple instances of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user.
When it comes to sending the notification on a specific date, I'm pretty sure you can set it up in the Firebase Console.
However, if you intend it to be sent from the server, you have to implement it yourself, since I think, there is no currently API available or a parameter you can set in the payload that can be modified for the message to be sent for a specific date.

Swift Firebase Send Push Notification [duplicate]

This question already has answers here:
Is it possible to send PushNotifications, using Firebase Cloud Messaging (FCM) to special UDID, directly from device?
(6 answers)
Closed 6 years ago.
I was wondering how I could send a push notification by code from my app, via Firebase? I am only able to send a push notification from my Firebase Notification-console as of right now, but I would like to figure out how to send one programmatically. Any ideas on where I can find more info on this? Please point me in the right direction! I tried to check out a project on GitHub by Firebase (quickstart), but I have to say that including that project, it's very little information on this. I was lucky to find a tutorial on YouTube that at least allowed me to teach myself how to use remote notifications.
Thanks in advance!
You can, Firebase (formally Cloud Messaging) provides REST API to send push notifications, checkout the following documentation,
https://firebase.google.com/docs/cloud-messaging/downstream
https://firebase.google.com/docs/cloud-messaging/server
You have to construct the payload, generate Server API Key from Firebase Console and send http request to Firebase endpoint (https://fcm.googleapis.com/fcm/send)
And if you are looking for any library, here is the one which works
http://www.java2s.com/Code/Jar/g/Downloadgcmserverjar.htm
it will send push to GCM server, but it works with Firebase too(we are currently using it)
i don't currently find any official SDK provided by firebase to send push notifications