Mobile Chat - How to store data? - chat

I'm trying to figure out the best way to store data for a mobile chat program.
Basically I will be able to make a group with my friends and they should also see the same group I made.
I'm assuming the best way is to store the data locally on each phone, and then when someone sends a message, it goes to the network, and the network sends that data to each recipients local phone so that it updates the local data.
That way when people are opening up the application, the previous few messages are still visible, since the program will check local data storage.
Is this the proper way to create mobile chat? Or should there be no local storage of data?

The best way will be to store data locally and on the server as well. The reason are as follows
Local data is for the users and will allow the saving on data costs instead of the users always having to get their chat data online everytime they logon. My assumption is that you want to have offline messages the way that Whatsapp chat client has.
Server data is for your reference and also good practice in order to provide the user with data up to a certain point in history if they have lost their device and they login to another device.
I hope this helps and answers your question.

Related

How to Implement "Your contact just joined app" feature

I am building a mobile app (in flutter firebase, but the answer does not have to be firebase specific). And I would like to implement a feature that notifies users whenever anyone from their contact list joins the app. This seems like a very EXPENSIVE feature.
At the top of my head, I see a lambda/cloud function that is triggered everytime a user joins and then searches a database of users and their respective contacts for the existence of the new user's phone number. To me, this solution does not scale well for two reasons: if the number of total users is in the millions and the number of users joining simultaneously is a lot.
My better solution is to get the user's contacts upon joining and then searching a database of current users contacts for any of the phone numbers of the newly joined user.
Is there a solution better than the second one? If so, what is it? If the second solution is standard, what kind of backend storage mechanism provides the best search and retrieval time for a database of users and their respective contacts?
In the case of large users ill not do first solution because that may slow the sign up process instead i will creat a cron job that runs at a specific time or periodically it will get the list of the latest users signed up that day or that hour whatever you prefer then that cron will check the new user if related to any user in the databases and send a notification right away, or a better solution create a temporary table in a database in another server insert the notification informations into the other server, creat another cron job in the second server it will run at a specific time to sendthe notification

What is a good way to identify mobile users without login?

I'm working on a mobile game in Unity and I want to be able to identify my user without them logging in (so when they send data to the server I will know it's them).
In this specific case, the solution doesn't have to be data-loss proof (meaning it's not the end of the world if the user loses access to their data on the server), but I really want to avoid situations where users can access other users' data.
Here's what I thought of so far: When the user starts the game, a random ID is created and saved into PlayerPrefs. From there, the game takes that ID, adds to it the IP address of the user, and hashes it.
This hash is then sent to the server, and the server keeps in its data the hash as well as the IP address the request was sent from.
From now on, every request sent by the user to the server needs to be signed by the hash and come from this specific IP address. This means that if the user clears PlayerPrefs, uninstalls the game or changes device - they will lose access to their data on the server.
Do you think this will work, or is this impractical/insecure/inefficent?
Thanks in advance!
You can identify device by its unique ID. Works for Android and iOS. (Documentation)
string deviceID = SystemInfo.deviceUniqueIdentifier;
You cant take the IP because it changes a lot on a mobile phone, you need to stick to a random UUID generated when the app is installed, maybe you can add something like the MAC address of the Wifi adapter because that wont change... but if the user is on roaming or using the cellular network is a guess...
Remember that getting hardware identifiers are against the privacy procedures of many countries and companies, i'll stick to generating a random UUID for each app install
https://developer.android.com/training/articles/user-data-ids
Programmatically getting the MAC of an Android device

iOS push notifications to large number of users

I saved users' device tokens in database.
At the time to push notifications,I loaded all device tokens from database,then in a loop,I send push message to one user one time.
Now there are about 300 thousands users,I want to know,is there any other better way?
Thanks
There is no better way with Apple. You need to send the same message to each device token. Services like Parse.com will mask this behind the scenes dirty work for you by letting you broadcast to groups of devices, however you still need to subscribe each device token to the group initially...
So, to answer your question, no there is no better way, you must loop and send to all device tokens :(.

How to check if a person in your iPhone contact list has an app installed?

I want to allow people to privately share data with each other using their contacts list to select people to share with. I'm planning on using Push Notifications to notify others that they have been shared with, but how can I handle those that do not have the app installed?
The cases are that I have their phone # and/or email. I can simply send them a message saying "X wants to share Y with you", but how can I determine if I need to send a Push Notification or an email/text?
If you're looking for API then you're out of luck. You can always collect this personal data server-side with agreement of your users. There you can also manage groups and other community relations.
Check here:
https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html
The crux of it though will be that you will need to store a token when the device is registered anyway to be able to send notifications to them, so you can use that.
And using The Feedback Service alluded to in the documentation, you can remove the token, should it fail too often.
But, as rokjarc said, if you're expecting a third-party API to exist, you're pretty much out of luck. Apple ahs done most of the work for you already anyway.
When the app registeres for push notifications you need to pass additional data to your server. The user could input their own email/phone which will be sent to the server so that users can find each other. The email/phone can be stored alongside with the push token. When someone wants to share something, you would search the corresponding push token in the database and send the notification through APNS. Note there can be multiple push tokens for one email or phone i.e. when a user has multiple devices.
The users of your app should be aware of the data which is stored on your server and should have the option to delete it. Also use the APNS feedback service to detect and remove invalid push tokens.

do i need to maintain a database for using push notification on my web server?

how we can maintain push notification for hundreds of devices? do we need to maintain a database on server or apple will maintain this,we just need to send payload.also i'm confusing in this matter that how do i cancel already sent payload...does someone knows about it?
You need to maintain your own database. The payload that you send to Apple includes the device token of the iphone you are sending the message to. Your table could contain as simple as an id for the user (auto-generated id, or email, or whatever you need), mapped to the iphone deviceToken, along with other columns and tables that you need for your book-keeping. The device token can be stored as String for simplicity, but it's really a 32-byte BLOB.
Once you send a payload, you cannot cancel or check its status. Once you send it, it's out of your hands.
I'd head on over to Urban Airship and play around with their implementation of Apple Push Notifications. They have a sample PHP application you can extend to fit your need and great step-by-step documentation on how to get your sample application up and running.
No, there is no way of canceling sent payload.