I am creating mobile application using latest version of Ionic 3. And I am at the point where I need to implement push notifications. I am using FCM. I have managed to done it for Android phones using this plugin: https://github.com/phonegap/phonegap-plugin-push. Reading documentation for this plugin, it says that for Android I should send only Data Messages and that that is the best practice. It also says that send Notification and Data payload would not work properly:
When your app is in the foreground any on('notification') handlers you have registered will be called. If your app is in the background, the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your on('notification') handler will not be called as messages that have notification payloads will not cause the plugins onMessageReceived method to be called.
But for IOS I need to send notification message with data payload. This would not be a problem if I target directly devices, however I need to send Topic Messages. So the way I see is that on my server I need to implement this logic:
Let's say that the name of topic is FOOD-AND-DRINKS:
function onSomeEvent($data) {
// send push notification to topic ANDROID~FOOD-AND-DRIKS
// send push notification to topic IOS~FOOD-AND-DRINKS
}
Also, since in the future my plan will include multiple cities, and not all people would like to listen for notifications for cities other the one where that person lives, so then my topic would be PLATFORM~CITY~CATEGORY.
So my question would be, is there any better plugin for handling notifications, or some service between my server and Google FCM and that service would take care of that, or this is quite OK what I have proposed?
You can use cloud functions to be able to send notifications since you are using FCM also.
More on this here: https://firebase.google.com/docs/functions/
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.
Using cloud functions you can use database triggers like onWrite() and it will be able to send notifications if you have data payload and/or notification.
But if you use data payload alone then you can send if android device is in background also.
Regarding Topics:
If you have multiple cities in your application, then you can let the user register to each topic. You can do in the database like this:
city-category
id_here
cityname: nameX
//other details
id_here1
cityname: nameY
//other details
Related
Using a serverless architecture built on AWS, I'm looking for the best way to have users receive near-instant notifications of new "chats" within my Android app. I don't necessarily want to see a push notification appear in the phone's notification tray - I just want the app to listen for new messages, and update the view accordingly.
Here's my thinking: every time a user sends a chat, I'd basically trigger a Lambda function which would call SNS or IoT to publish the notification to any subscribed users of this chat.
But since SNS / IoT both work by sending "push notifications" to the phone, does that mean the message would have to appear within the phone's notification tray? I'm just looking for a way for my app to silently receive near-instant notifications from AWS and execute code to update its view.
Some other notes:
1) I don't want to build this using a server / EC2 with websocket listeners - I'd rather go serverless.
2) I've looked in Google's Firebase real-time DB which looks very capable, but as the rest of my architecture is on AWS, I'd like to stay there if possible
If you are making app for Android only, you can make use of the data message in FCM from Firebase. You can handle the message in onMessageReceived no matter your apps is on Foreground or Background.
Apart from that, firebase provide integration with most server side language. You should be able to send the message in your lambda function.
my suggestion is using FireBase...
and make your Json tag with "data" than "Notification"
I have a cross platform application and i want to send notification to sign in users about their messages.
Now I confused about uses of push, local notifications.
What I think of Push notifications is that it is for sending Announcements to users which is not specifically related to their account only.
Can anyone help me out with what should I use? I already used Local notifications in one of my applications with such requirement.
It mainly depends on; is the data coming from local or remote?
You cannot control when your users open the app, and only when they open the app (with a few exceptions) you are able to fetch data. Then with that data you would be able to schedule a local notification. But in most cases that doesn't make much sense, because they have already loaded and probably seen the data. It only makes sense when you schedule an alarm clock for instance.
When you want the data to come from remote, like when they receive a message, you will have to use push notifications. The user is then alerted that new data is available without having to go look for it themselves. It is pushed to them.
However, for push notifications you will need infrastructure which you did not when using local notifications. You will need a server to handle the push notifications (Azure has some awesome functionalities for this) and some trigger to send push notifications. This can be an insert on a database, or a scheduled task. Also, the user has to enable push notifications and your app has to register itself to be able to receive them. It can be a pain to implement it the first time.
It depends on for what reason you're sending the notification.
A local notification is sent locally on the device, so it doesn't need an internet connection. Examples could be:
Send a birthday message when the user has birthday
In a harvesting game, send a local notification when the store is full
A Push Notification is sent from a server and it requires internet on your device to receive it. Examples:
You get a message in a chat while the app is not open (if I understand your question right, this is your case)
In a game: realtime events which are triggered by a server
So in your case, if guess you want to notify the user about new messages if he does not have the app opened. This notification comes from a server and is a Push Notification.
As you describe you want to send notification about sign in users about their messages. so it would be the real time notification about when there is message for user you need to notify the user. so apple having PushNotification is the best approach you need to apply for this. using that you can directly notify user about the new messages.
Why LocalNotification is not useful in this scenario?
I think messaging is the realtime stuff. local notification is not for that. its for only managing local notify stuff. like reminder OR to do added task.. and many more
Is it possiable to set an on click button which will send a push notifiacion message to a user on fierbase? I seccssed sending a push message by the website but I really need the option to send messages from the app.
Thankds!
You can do it now with Functions. This means it is perceived as if were done by the app, but it is a longer way.
For start, there is no such a thing as an app to app Firebase Cloud Message, is very confusing because the Firebase Database is real time.
What was done before Functions, was to make the app trigger something on a server, and then the server will make FCM send the push notification.
Now with Functions, you don't need a server. Functions can listen to changes in the Firebase Database (also can listen to user creation) and can send Firebase Cloud Messages. So the complete flow is this:
The app will trigger a change in the database
Functions will be
listening to that node
When the changed has listened, then a push
notification will be triggered
If it is needed, Functions can
request data from other nodes, to get the device token by example
This is the Functions documentation https://firebase.google.com/docs/functions/
Currently, Functions is in beta so, please see the samples here https://github.com/firebase/functions-samples
And here is a personal sample, which is heavily commented to clarify all the problems which I went https://github.com/cutiko/testing-functions
Good luck
I have cloned and ran the github https://github.com/firebase/friendlychat friendly chat project for Android. It is creating chat app between all users but I was expecting to see a notification since they have included FirebaseMessagingService in the code.
AM I expecting to much or I need to change something in code to get notification in my notification bar?
Any direction would be helpful.
Ok I was way off in my question.
So, in order to have one on one notification I had to create php files in my own server. My server code will have FCM key from firebase and when user sends a message, I send a push request from my application to server including receiver's FCM token, it will send a notification to Firebase and Firebase will send notification to the receiver.
Google have firebase functions and somehow you don't need your own server anymore but I am not sure how to implement that.
I am creating a simple forum app for ANDROID using Parse. I am stuck at a problem related to notifications
For instance I want that when user A posts a comment in a forum app, user B (who subscribed to that post) will receive a push notification, can I do that using either client code, instead of handling it using Cloud Code, or the REST API? If not then how to I start developing the server side to use cloud code or REST API
Allowing users to send push notifications via the client is bad for security reasons. It's not incredibly difficult to get the application id and client key to an app. Anyone with that information will be able to create their own code that allows them to target whoever they want with push notifications if client push is enabled.