iOS push notifications with Firebase FCM to a specific user - ios

I am trying to send notifications to users when something happens in their account, for example a new friend request or follower, or a tag in an image. I have been looking into Firebase FCM to make this happen but can't figure out how to send push notifications to just 1 user, based on some activity in their account.
Is there any way this can be done in FCM or are there are any other methods out there to make this happen? I'm new to iOS dev and push notifications, so any help will be greatly appreciated!
Thanks!
PS: If I do need to make my own server for this, could someone point me to any resources to do this in python? I've seen quite a few posts for APNs servers in PHP, but I don't know PHP that well.

The easiest way is to use Firebase Cloud Functions , I have experience working with it using Javascript then trigger the function when something changes in database. You can also send a http request with the specific device token which you want a push notification to be delivered to, then the function will do it's magic for you. Firebase have ready to use samples from their Github repo.
NB: - For your case if you really want to use Python then check this answer it might help you get started.

Related

How can I go about setting up push notifications using firebase cloud messaging and cloud functions?

I'm been coding for a year now and know swift really well and the basics to javascript. I've built a social media like app and its completely done besides the push notification functionality... which i've been struggling with for quite a while now.
I'm having trouble figuring out how to implement these in order to send notifications like when a user follows another user or they receive a new messege.
I don't understand how to integrate the cloud functions that I would write using and node.js with my xcode project.
When I look for documentation online its usually just how to send push notifications using the firebase notifications console which is cool but doesn't trigger based off specific user actions or events (ex: when the user gets a new follower)
I think since im struggling with grasping the concept of how to implement it, the actual technical set up of it makes even less sense. Any advice or resources would be greatly appreciated.
Thank you
Conceptually, what you have to do is set up server-side processing of your database to manage when events occur. This is what the Node.js code will be. Everything is connected through the database-- your Xcode and Node.js code work independently, but both communicate with Firebase. You can create a Cloud Function that will automatically run when it detects changes in your database, and this will automatically send push notifications.
I've done a similar project-- I set up a listener for my Realtime Database in my Cloud Function. Every time the user got a new follower, i.e. their followers tree was updated, I sent a notification to the device using an FCM token (which I also stored in the database).
exports.onTimeEnd = functions.database.ref("users/{user}/followers")
.onUpdate((snapshot, context) => {
// your code here
}
In that block, you can call a .once() to find out the user's token to send them a notification with.
https://firebase.google.com/docs/functions/get-started
This link here told me everything I had to do in regards to set up in the terminal. Super helpful.

How to go about IOS Push Notifications?

Im currently developing an app in Swift. I'm at the last stage of the app where I just need to integrate push notifications to the lock screen when certain user actions occur.
I'm going for something like how Instagram sends a push notification when a new user follows you or likes your post.
My entire backend is using firebase, and i've looked into firebase cloud messaging and I dont know if it has the capability to perform notifications like this.
I've watched tutorials and read documentation and I know you can push notifications to users from the console but I'm looking for notifications to be published and pushed based off specific user actions.
I know this is a very broad questions so what I want to know is:
A) Are notifications like instagram possible through Firebase cloud messeging?
B) If not, can you point me in the direction of how to figure this out?
Thank you!
A) Are notifications like instagram possible through Firebase cloud messaging?
Yes
Firebase send the push to APNS first then APNS send push notification to iOS devices.
If user 'A' do any action then that specific action will be transferred/send to staging/production server via apis. Based on your business logic staging/production server will send push notification to users(FCM token).
I hope this is helpful or you can explain the exact issue your are facing.

Push Notifications with Firebase and OneSignal

I'm looking for some guidance.
I'm using Firebase as the backend server for an app I'm building and I would like to alert users when somebody has either liked or disliked some content the user generated.
I understand that Firebase offers cloud messaging through which I can target very specific users and send updates to them; I have implemented that functionality. However, I would like to send updates based on changes in the database, and, as far as I understand, FCM is not built for this purpose.
I have come across OneSignal and it seems promising. Has anybody implemented this with Firebase and could it do what I'm looking for?
Thanks!
I have it set upon such a way that when a message is send by a user to another user, a notification is also send via OneSignal. You just need to store the OneSignal userId in a node with the firebase user UID.
I you like someone's content, then that would also send a notification out directly to the other user.

How can I send Parse push notifications to users after specific user action?

I have read a lot of tutorials and doc but I cannot quite wrap my head around it: I am trying to send users of my app a notification when somebody posts something new or if someone likes one of their posts (think Facebook-style table view displaying notifications as they happen). The certificates are set up and the app is able to receive remote notifications that I send through the Parse push console.
Obviously I want to send a notification as the actions happen, but I am unsure how to do that. Parse suggests using cloud code, but it seems to be in Javascript. Is there a way to do it in Swift? My first idea was to send the push from the users' devices as they interact (when the user likes a pic from you, he sends the push and you receive it) but apparently, it is discouraged as it is unsafe.
I understand my question is general, but I am lost as to how I can tackle this issue: can anybody give me an outline of how this should be dealt with? Not necessarily precise code, but a general idea of what I should do?

Consuming external json with parse.com

I'm working on an iOS application developed with Swift. The application is going to need notifications to receive alerts when certain events occur.
To handle push notifications I'm using parse.com. I was able to create an account and integrate push notifications into my application, as it's explained in the Parse.com guide, and are working fine when I send something from the Push section.
What I'm trying to do, and I cannot figure it out, is consume a 3rd party JSON, process that JSON to check some status and report, to the users that are using the application, a status change via a push notification. I know I should process all this in the backend/server side and then push the result or what I'm trying to notify, but I don't know what to do.
Ex. of What I'm trying to archive:
3rd party website ---(json)---> parse.com ---(push notification)--->
My App
I'm aware the tools that Parse.com provides, such as REST API, Cloud Code, Webhooks and Jobs, but I'm totally lost here! I cannot find any guide or documentation that allows me to do what I previously described. I don't even know if its possible, and the documentation at parse.com it's not necesarily up to date.
I hope anyone can help me, or guide me, if parse.com it's not enought for my purpouse.
Thanks for reading.
I would suggest looking into Cloud Code or a Job from Parse and seeing if you can get one to run on a time interval to look for updated JSON.
You can decode JSON using JS, which is exactly what Parse Cloud Code is, you actually write it out on your own computer and then upload it. I've only use the afterSave functions. I would think you probably have to keep some type of object in parse to see what is updated and notify who ever needs to notified when that data is updated.
Also, you'll probably want to pass something to the app to actually update when the user selects the push alert. You can do this in the push alert itself. It converts to a dictionary in the app delegate's method for handling received notifications or launching with one.
Alternatively, if the web server is under your control, you can create a PHP script that will trigger the push to parse.
My best shot at this (after not having used Parse for a long while) would be to set up a Job on Parse that queries the 3rd-party service, and takes that response and throws it into a Cloud Code function, which in turn parses out that JSON and sends off a notification.
Parse's reference materials would probably be a good starting point.
The toughest part for you is the up-to-date-ness of your data. Since you're still polling that 3rd-party service at a regular interval, it's going to be a trade-off between freshness of updates and frequency of jobs (which cost money at a certain scale).

Resources