I am creating an app using Swift and Firebase. When the user presses a button the app will upload some data to the real time database and send another user a Push Notification. Is possible by making the other user subscribe to the changes in the realtime database or will this not check for changes when the app is not in the foreground?
Should I upload the data then use Cloud Messaging to alert the user of the new data?
Thank you
You should use FCM for this use case. Having the app listen for changes to the database while in the background is not good for device battery, so you should have your application server listen to the database for changes then send appropriate FCM messages to let the client app know that there are changes.
Related
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.
We have a requirement to save the push notification while the app is in active or killed state, and later show all these saved notification in a view controller when ever user wants.
Could anyone help me with other optimal approach around this?
Few that I could think of were:
Save it to user defaults, and when app launches or when user goes to the notification controller, move the data to Core Data and clear the user defaults. I was also thinking of limiting background saving to user defaults to be 10.
App groups. Using core data in notification service extension. We were facing issues with accessing App Delegate from this notification service extension
Please note, the notification cannot be sent by the server. Also, I am curious about the scenario where app can be unused for few weeks but notifications will keep coming.
I'm working on an iOS application, and want to achieve behavior like push notifications using firebase real time DB.
In case my app is listening to some firebase node and i'll send local push notification to the user in case that node is updated.
The issue is, if the app is not running i.e. user has killed it, will my app continue listening to that particular node?
I guess, in Android we've support like this, as explained in this link (Link).
Can we achieve the same behavior in iOS. If no, what can be the alternative?
Thanks
Update:
1- There's nothing like triggering push notifications locally in iOS app. I wanted to achieve remote notification's behavior and that can't be done.
2- As far as listening to some event is concerned, it can't be done when app is not in foreground or background.
You can’t do anything if an iOS app is killed/not present in memory.
However, you can do some tasks if app is in background, and is present in memory.
You can use background fetch request in this case.
In Android, there are Services which run even when the app is killed. But on iOS, there is no such thing like this.
You can add Firebase observers in your root view controller, and implement background fetch request to continue observing data when app is in background.
When you app is killed, the listeners are disconnected.
The typical way to send messages to your app in this state is by using a push notification, which in Firebase maps to Firebase Cloud Messaging.
This is why you'll often see the Firebase Database and Firebase Cloud Messaging (FCM) used hand-in-hand: the database is used for messaging while the user has the app open, and FCM is used to send messages when the app is not active.
I want to save all the notifications from server.Is that only way is to request server to get all messages?
You may use silent notification feature which lets your app do simple operations (e.g. purchase sync or file sync) without bothering the user or having the user open the app.
I am create a firebase based chat application for iOS. One of the features is to send push notification to the users in the same chat room (if they are offline).
I can't find a firebase function (for iOS) that can be used to send push notifications to the user.
Is it possible?
Displaying alert badges and notifications on iPhone applications is accomplished through Apple's Push Notification system. Since the application is not running on the user's phone when they receive notifications, the APN will have to be triggered from your server-side code.
You'll probably want to create a server-side module that listens for changes to your chat Firebase. When a message appears for a user that is offline, you'll have to schedule a remote notification with the APN. That latter part has nothing to do with Firebase, but has extensive documentation on Apple's developer web site.
I'm not sure if a web application can display alerts or badges. Otherwise this approach will only work if you create a native wrapper for your Firebase chat application.