Trigger Notification in iOS upon change in Firebase Database - ios

I'm using FirebaseUI to populate a table from the Database, hence, it also listens to changes, e.g. when a child is added, it automatically gets inserted into the table.
Now I'm trying to implement a notification upon that exact even, meaning when there is a new child added to the DB, there should be a notification that a new child has been added.
What is the best practice to do so?
I'm aware that there are Remote Push Notifications (what Firebase offers through its console), but this here is something else right? I guess there is a way in which the app itself notifies the user when a new child is added, but what happens when the app is closed?

With the new feature Cloud Functions, you can do this without any need of an external server.
See my response there for more details : Firebase notification on child added/modified

You're looking for Firebase Cloud Messaging, which is what Firebase Notifications is built on top of. Note that you will need an app server to run the code that listens for the changes to the database and then calls FCM to send the notification to the user.

Related

Send currency in push notifications via Firebase Cloud messaging

We are able to send currency via the Custom data parameters in Firebase Cloud messaging (see SS below).
But if the user does not tap the notification "YOU RECEIVED 15 FREE GOLD!" then Firebase.Messaging.FirebaseMessaging.MessageReceived is never fired and the user never gets their currency. So the user may see the notification, and then be disappointed the next time they open the app and there is no gold.
Is there a way in Firebase to compose the notification so that the notification can be accessed even if the user did not tap the notification to open the app?
Without tapping on notification your application not launch and custom data you sent through notification is not received to the application. So sending custom data through firebase push notification is wrong choice in this scenario. You should sent custom data whatever you need through API is always good choice. You can also use firebase database and in that you can send custom data using nodes for respective user.

Receive notifications from firebase in background on IOS App?

I am creating a framework that can receive custom (a certain data model) messages from firebase. The framework is going to be implemented to receive notifications that are not related with the app but with other stuff.
So the framework is going to handle all the display issue by translating the data received and create a notification as it is indicated (I have some flags in data receive that indicated if I should use an image or attach an icon .. etc).
So I did some research on how to receive messages from FCM.
In first instance, I found direct channel that allows to bypass APNS, the problem is that, this only works with the app in foreground.
I indeed create a test project in firebase, a single view app, register my app in firebase project, set info.plist, configure , and send a notification to my app and It worked (just when the app was open).
Then I looked for another choice, and I found APNS. Skiping all the process for validation between firebase and APNS. I found that when you have all set up (and you put all initialization in didAplicationFinishLaunching) your app is able to receive notifications from firebase (Through APNS) when applicaton is in background.
But, notification received (the one that gets displayed) is just for you to tap over it and then it will fire up the app again an only then you will receive the whole data in aplication:didReceiveRemoteMessage method.
My question is, is there a way I can get this custom messages even in background and when received I can display a notification with the content of the whole message?
Yes,
Fortunately you can do that but for that you need to send Silent Notification which will let you process the notification in background and schedule local notification to trigger it with you desired data.

Keeping Firebase DB listeners active when view controller isn't active

I have an iOS app with the Firebase Listener on the home screen viewController.
However, when the app is in the background, or the user is on a different viewController, the listener don't update - the data rush back when the viewController re-opens.
The Firebase DB data is used across the entire app, so I want to have the data constantly up to date (preferably while the app is in the background too).
This problem is especially prevalent when the user receives a push notification of new data, but the user can't see it in the app because it hasn't yet downloaded (the only other option would be to send the data with the push message but I'd prefer to avoid this)

Swift: Push Notifications not working after implementing Realm Database

I have a small messaging app and user receives a push notification whenever the user gets a message. Recently I have implemented Realm Database for my app. I am storing all the data that comes from the server into the realm directly and displaying the data to the user from realm. So, after shifting to this way the push notifications are not working. But again if I download the current version that is in the AppStore, the notifications are working. Every message has a messageID and we are sending the messageID as one of the parameter in the push notifications. Can someone help me on what I can do to make the push notifications working again.
Well, for getting push notifications to work, you not only need to configure the app correctly, you also need to configure the backend service & APNS linking correctly to get it to work.
You should try a methodical approach wherein you divide the entire feature implementation of push notifications into smaller sub-tasks like app side logic, backend configuration, Certificates & Provisioning Profile setup, etc. Try to examine each of these sub-task implementation & surely you would find the culprit. Since, you know the existing App Store version of the app is working,you have your task reduced

Sending Push Notifications When a Firebase Real Time Database Node is Updated

I have created an app which uses firebase real-time database and storage. My app allows users to message each other, but I am not sure how to notify the user when they have received a new message. I store all of the messages in one node called messages. I then store the message relationships in a different node called "user-messages". How do I monitor the "user-messages" node to alert the user with a notification that they have a new message? I am familiar with observing event types and such, i.e.: .Value and .ChildAdded, but I am not sure how to trigger an event to send the user a notification.
edit: gave a little more clairity.
So I accidently did not see that Firebase can use Google Cloud Messaging which seems to be able to do what I want. For future reference firebase has put the IOS setup here :Firebase Cloud Messaging SetUp
Like you mentioned, you can use child_added event to monitor whenever a new message is added to user-messages and firebase will call your event handler whenever a new child is added.
ref.child('user-messages').on('child_added', (snapshot) => {
// Read the message and send notification here
})
You may want to update the user-message as well after it has been handled so that you don't end up sending duplicate notifications when your app restarts.
What I did was set up an XMPP server with Ejabbered in order to conduct notifications. Hope the following helps.
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
https://firebase.google.com/docs/cloud-messaging/server#implementing-the-xmpp-connection-server-protocol

Resources