Firebase notifications Swift - swift

Yes I know that this has been asked on StackOverflow before but I just can't find exactly what I am looking for. So what I would like is when a user (user1) send a message to another user (user2) , for user2 to get a notification saying they have a new message from user1. So far I have set my app up so that I can send a push notification from the Firebase Console, but not so that the app does it automatically. I think I need an observe function but I am not quite sure what to do or the code for it?
Thank you so much for all the help! This is my first time with Firebase.

You can just use Cloud Functions.
It simply triggers a Function when an Event occurs.
For example whenever a new message added to a node you can run a function that sends a Notification to the user
Check the Documentation
Also check this sample which matches what you need

I have asked same question some time ago. The thing that was bothering me was why should I use Cloud Functions and write and deploy functions for it in javascript if I just wanted to send Notifications just between two users?
So I checked out other options and setup everything in just about few minutes without writing any javascript functions in the Firebase Cloud Functions.
Well it depends on what you will exactly need but in my case using Cloud Functions just to handle that was nonsense. If you are in the same situation as I was you can use OneSignal like I did. There is also my question on this and you can check it out here.

you can try this it can worked for me sending notification through fire base cloud
https://github.com/firebase/quickstart-ios
https://github.com/firebase/quickstart-ios/issues/286#issuecomment-304992090

Related

How to send push notification when data changes from API

I'm currently creating an iOS application in Swift that fetches data from a third party API and then displaying it on the screen.
One of the features includes enabling push notification so that the user gets a push notification if there's a change in the API data.
However, I'm struggling to figure out how to implement the push notification side of it so that I can constantly monitor the API data and then send out a push notification when there's a change in the data.
Can someone point me in the right direction on how to do this? I've previously used Firebase to implement push notifications but the push was triggered from a user action. I was wondering whether there's something similar I can utilise in Firebase or if there's any other recommendations?
Thank you!
You may be able to use cloud functions. If you're monitoring the data client side you can perhaps make a call to a cloud function to send a push notification.
Or you may want to look into local notifications. I'm not sure exactly what you're trying to accomplish so it's tough to really say, but as far as a direction goes I would recommend checking out cloud functions and local notifications to see if either one solves your needs.
Edit:
Now that I know more what you're looking for I would check out this article here. It will explain about Background App Refresh. Here's an excerpt from the article.
When the system calls your app delegate’s application(_:performFetchWithCompletionHandler:) method, configure a URLSession object to download any new data. The system waits until network and power conditions are good, so you should be able to retrieve adequate amounts of data quickly. When you finish updating your app, call the completion handler and provide an accurate result of your outcome, which can include saying that no new data was available.
So in the application(_:performFetchWithCompletionHandler:) method you would want to:
Download the new data
Compare it to old data and see if there's been a change
And then probably I would just display a Local Notification to the user.
I think that would be the easiest way with your current architecture and without having to write any server side code.

Best way to trigger notification in flutter

My flutter app allows users to schedule events and needs to notify them when the time comes. These events involve multiple users and may be deleted. I am looking for the best way to trigger the notifications.
So far, I have found 2 packages that may be able to achieve this: firebase_messaging and flutter_local_notifications.
With firebase_messaging, I thought of creating a cloud function that would be triggered when an event was created in firestore, which schedules another cloud function to be run during the event, checking whether the event still exists in firestore, and triggering notifications accordingly. However, I am unsure of whether it is possible to schedule a cloud function from within another.
With flutter_local_notifications, my issue is that user B may create events involving user A or the event may be deleted whilst user A's app remains terminated. As such, the scheduled notifications for user A have no way of being adjusted accordingly.
What do you think is the best approach?
If you need to involve multiple people , flutter local notifications isnt for you. It is not build for that.

How can I run server-side realtime database queries

I am using Firebase's Realtime Database.
I am able to use my old device and permanently keep it on for checking if the host has left a party to therefore notify the users. However, this is inconvenient and there must be a simple server side solution.
I know how to code it (using .observe etc.) but I don't know where to run the code. The code will be on a loop to check if a host has left every 10 seconds (this is because the host may run out of battery so the database is not notified). Can I simply run it in functions somehow? Or using hosting?
The server code will send a request to the host, and if there is no response, the party has therefore been closed so it will tell the users.
Any help or pointers in the right direction are greatly appreciated.
If you have any questions, please ask!
It's not related to the iOS. Put your initial code into the viewDidLoad or init methods (depends on how do you write the code) and forget about it. Those methods are called once per an instance. For now Firebase works fine on your usecase. At least I don't have any wierd updates on the observe method. also you can specify what do you want to observe exactly in the Firebase (something like the new or last 15)
The solution to this was that even if the user left the app, they would still be in the party. I used user defaults so it can remember if the user was in a party so it can return them.
I also used Realtime Database triggers which can remove all information about a user with one action in the app (so all data gets removed, and not left behind, which would create a waste of unusable database memory).

Creating event reminders

I am working on an ionic project. It is based on medication managing.And I want to remind the user about their medications. I am new to this and can some one give me a sample code, link or something to create reminders.
I would recommend taking a look at Local Notifications, they are notifications that can be scheduled on the device without the need for a server. It is commonly used for things like reminders. You can also choose to do this using a server with Push Notifications, but that doesn't seem necessary in your situation.
For starters, take a look at the documentation for Local Notifications, see if it works for your use case.

In-App Notifications?

I'm trying to create functionality in my app that would allow me to release news updates (Via a server) to those using the app, similar to what is found in Doodle Jump:
http://farm8.staticflickr.com/7143/6463110847_d485681dac.jpg
Any sample code or ideas would be helpful.
You'll probably need to create an API/web service that your app calls on launch (or when entering foreground)...you could populate that with a database that just gives the entries since the last sync...or just returns some response that you've set up. The response should be JSON or XML formatted (I vote JSON) and then in your app, you call it, parse the response, and place/manipulate it however necessary
http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/
There are a lot of options here. In any case you will need a web server that hosts these news postings. The route that I would take is some kind of blog site, where you can easily manage posts. Then upon launching the app you make a web service call to said blog and get the news posts. You will need to keep track locally of which posts were read by the user in order to keep the badge count correct.
You could also roll your own server, but I don't really see the point for something so simple.
Another option is a web-service such as Parse
This question is too vague for code samples as we would be essentially writing the entire solution for you in order for it to make sense.
If you have further questions into how to leverage these web services, how to load the feed, how to display it etc... Break it up across multiple questions.
There's a service doing this called Converser, if you're still looking.