Parse: Basic App to App Communication - ios

I am trying to figure out what the basic steps are for getting data passed between users. For example, say I, a user of the app, want to send another user of my app a message or a geopoint or some other form of data. I know the first step would be posting the data to Parse, which I don't have a problem with. But then, how would the other user know there is data to retrieve and also how would they go about retrieving it. Are push notifications the proper and only way of letting the recipient's app know its being sent something? When the recipient app knows there is data posted intended for it to retrieve, how does it go about locating it with a PFQuery? Does the posting app need to supply the receiving app with a UID of some form that the receiving app can then use in its query to locate the data? This is kind of the last puzzle piece for my app and unfortunately it's the only thing Parse didn't make clear to me. It is more than likely user error on my part not finding the correct documentation but, app to app communication is key in most apps and so I need to figure out the defacto way that Parse accomplishes this. Thanks in advance for any help!

You can have a relational table lets say "Messages" table in Parse,
with properties, sender (Pointer to a User), recipient (Pointer to a User) and message (String). and maybe a 'read' Boolean.
You could then query the messages table, With something like:
PSEUDO:
get all messages where recipient is equal to logged in user.
and display these messages on the UI.
Its pretty straightforward, I have done simple messaging service with Parse before

Thanks guys! In the end, I think it is best for a device to not have to be querying for changes but rather to be notified when it has new data to retrieve. Thus, for my uses, I think a combination of your answers, especially with the "onSave" hook function mentioned by Bruno, is the best solution.

Related

How to invite users to join a multi player Gaming Session using Parse (swift)

I'm trying to develop a trivia app, much like Quiz Up but with multi players.
Here's what I thought of doing:-
Creating a class called 'Game Session' on Parse, that has information of who created it (PFUser.current), the name of the gaming session(name), and the names of users invited(invited_users). Think of this Gaming Session as a closed group where the users interact with each other only.
So there's a createSessionViewController, and a joinSessionViewController.
If User A creates a gaming session (in createSessionViewController) and sends invites out to User B and User C, they get to accept or decline these invites in joinSessionViewController.
Now from what I have researched is that I would have to query through all the objects in the class Game Session (in viewdidload of the joinSessionViewController) and use query.wherekey for eg, User B's object id is in the column "invited_users". If so, I return that Gaming Session's object. Is that right?
If that is the case, is that an efficient way of doing it? Because it seems like if the app gets popular and there are lots of objects in the class, then it could take up a lot of time to get the one object with User B's id.
I hope I made myself clear and you guys understand my question.
PS: I'm sort of new to parse and swift, so if you could give me detailed answers it would be much appreciated.
Your logic is correct but I would also strongly suggest you take a look at Parse-LiveQuery. This tool allows you to subscribe to a PFQuery you are interested in. Once subscribed, the server will notify clients whenever a PFObject that matches the PFQuery is created or updated, in real-time.
https://github.com/ParsePlatform/parse-server/wiki/Parse-LiveQuery
https://github.com/ParsePlatform/ParseLiveQuery-iOS-OSX
Your assumption is correct and that is indeed one way you could go about doing that although it has drawbacks as you mentioned. If you felt like putting more effort into it, you can write JavaScript parse cloud code that executes after an item is saved (for example after a game session is created) and send out silent push notifications with the new objects id to the users who were invited. You could then use that push notification data to know the exact ids instead of having to query for them. This is much more advanced though. For whatever your app is, the simple route of having a model query the data on load should be fine. If you find yourself in a situation where performance is hindered due to this, well then congratulations.

Fetch all users from Firebase with Facebook login - swift

My app is using Facebook login only at the moment. I am trying to build a search function using the UISearchBar.
So my question is: Is it in any way possible to fetch all users from the Firebase database into an array? Maybe even get their UserID as well??
If you want to see any piece of code let me know, I just did not think it was relevant to this question :-)
If I have understood what you're trying to achieve then you should simply be able to save your users to the Realtime database upon registering/authenitcating your users.
After this you can perform a simple observeSingleEventOf to get all your users at the correct path, something like this:
rootRef.usersRef.observeSingleEvent(ofType: .value).....
Then with the completion handler you should get back a snapshot, the snapshot.value will include all your users.
*Please note that you don't need to stop observing this method since it will observe the values once then immediately stop. So I don't think you need to worry about memory issues.

Firebase data structure for chat app

I'm looking to basically remake Kik within my app. For most guides I've seen on a firebase chat application, there is one major Messages node, and then underneath that there's a fan-out with messages for each user that reference messages in the main list.
With the way my Firebase is laid out at the moment, it would be easier to implement something like this:
users
chatPartners
02834092890428
chatMessages
2093840923840923
timestamp/userUID/etc.
and just have the actual chat inside of my user's node. This seems to also cut down majorly on having to sift through every single message in a messages node?
So when the users send messages to eachother, I'd update the "chat messages" node under the sender and the user.
Is there any reason NOT to do it like this? I see everyone doing it the first way I described, yet I don't see a reason why storing each chat under user--->chat partner --> the chat log would be an issue.
The only issue you may run in to is how the data is called. Note that when you call the 'Chat Log', because it is a child of 'Users' and 'chatPartners', you will be calling the data of everything in that branch, essentially loading every piece of data in the database under 'Users', which is time and performance sensitive.

Multi user authorisation on controller actions

I’m building a small application that will have multiple users using ASP.NET MVC, but I’m not sure how to handle user authorisation in the scenario below. I may be missing something obvious as I’m still learning, so any advice is appreciated.
Basically, to illustrate my problem, consider that I’m building a very small email like messaging system. Here is the action to read a message:
/Message/ReadMessage/1
Where Message is the controller, ReadMessage the action and 1 is the MessageId.
Now this message was for “Bob” and in the db his UserId is stored with the message. Another user called “Fred” has also received a message and the MessageId for this is 2.
In my application, there would be no way for Bob to see Fred’s messages on the page directly or through links (messages should be private to each user), so what is the best way for me to protect from Bob simply changing the MessageId in the URL manually from 1 to 2 and viewing Fred's message?
As a current solution to this, I have a very simple check at the beginning of my controller action which compares the UserId stored with the message to the current UserId and if they don’t match, the user is redirected (to say, their inbox).
Is this a suitable solution for such a scenario? I get the feeling that while this works now, it isn’t the best approach to this problem. Thanks for the help.
your controller needs to check that the current user is allowed to access the resource ( message in this case )

Transfer Data From App to App?

Heres my plan. Two people have my app and I need to get a bunch of data from one to the other.
The person receiving the data doesn't know that they might be sent something, they two people could be in completely different places in the world, so it can't be transferred locally.
So, our of maybe thousands of people who use the app, I could have it, host a bunch of data and then only my specified receivers could then get that data from me and have it in their app.
I am VERY new to server/network stuff, so as much detail in your responses would be hugely helpful.
Any help or tips on how to do this would be much appreciated, thanks.
Sounds like a classic client server.
Setup a server.
Have app from user A send data to server.
Send push notification to us B he has new data.
When user B open the app have him poll the server for his new information.
Store the data in an online database.

Resources