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

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?

Related

Does AWS Pinpoint support push notifications inbox like SalesForce?

So I was looking through this and didn't find anything like it there, so the question is does pinpoint have the functionality to get all messages sent to the concrete user as SFMC does? Or do I have to create logic to save manually all received messages? I am working on Swift if it makes any difference.

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.

user to user push notifications

I have seen many questions on here and online that address this topic, but they all are from a long time ago, and are possibly outdated. I wanted to get a more recent answer if Firebase has implemented anything recently that is capable of a user to user push notification system, essentially what is used in all chat applications, or if the best option is still currently using Onesignal.
Yes! These days, you can use Cloud Functions for Firebase to do things like send a notification when something interesting happens on the Database side of things.
Here's an example where a user gets notified via notifications when they gain a new follower. Obviously, your part of the database portion will probably change depending on what exactly you want to trigger a notification, but the general theory is the same.

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).

How to aggregate iOS push notifications using Parse

so I'm developing an application where a user might get a notification based on some action but I only want the user to receive one notification of a specific type. An example might illustrate this better:
Say a user on facebook makes a facebook post. If someone likes the post they'll get a notification. However, if 20 different people like that post I don't want 20 separate notifications when they finally check their phone. I want one notification that says '20 people have liked your post.' I also only want to track the new notifications. Say 20 people have liked your post. I don't want the notification for the next 5 who've liked your post to be '25 people have liked your post.' I want it to be '5 new people have liked your post.'
What I don't know how to do is delete a notification that got sent using Parse. An idea I thought of off the top of my head for recording new posts was to keep track of what the user has seen for that post but that seems silly. It's a large amount of data to keep track of, compared to querying for a previous notification to that user for that channel (is that possible?).
Anyways, I was hoping other users of Parse using push notifications might've faced this problem and how you all might've gotten around it. I would like to implement my own backend but I don't have the expertise and I'm currently focused on the client side. Any help or suggestion would be greatly appreciated. Thanks!
The thing is, you have don't have the control to cancel a Push Notification. However, you do have a control when to send even how to send it. If you want to implement something like you say, you have to do custom works on that. You might observe a period of time like 2-3 minutes whether there are more than for example 10 notifications you want to send. If so, send one instead.
Before iOS 8, Push Notification did have so many limitations like we can not have our own custom action. But now, I think Apple will let us do more as time goes by.
This might not be the best way but here's how I plan on implementing the feature. I'm going to add a notifications array to the user ([Notification objects]), this will also allow me to query for notifications for a possible notifications page. Say this were facebook and the user gets a new like notification on a post (1 like total).
I will create a new notification object and add it to the User object's notifications array with properties 'seen' set to false, 'prevNotificationLikes' set to 1, and then send out a notification. The message will be generic for singular/plural #'s of likes.
If someone else likes the post before the user responded to the push notification, I will see that the user hasn't 'seen' (false) the first notification and I will not send out a new notification.
Say 19 people like the post and then the user checks the initial notification and sets the 'seen' property to true. The next notification check on the cloud code for the 21st like will query to see if there are any previous notifications for that post/user. Parse cloud will then find a corresponding notification for that post/like where prevNotificationLikes is equal to 1 and update that number to 21. If the 'seen' property is set to true, then it'll send out a notification '20 new people have liked your post.' I know that the notifications are sent 1 step late with the fact that the user probably already knows that 19 people have liked the post but it'll be a compromise to get the job done.
Any critique is welcome. Sorry for wall of text instead of code. I'm just writing out my idea before writing the code so that I have something to follow along.

Resources