So Guys, how i did this:
I have my own server, where i’m using first apple and gogle push notification solution (simply i can send pushes).
Then i wrote few api’s, like send message, store messages in mysql, load unreaded messages, etc… (the app have more functions what are working over api requests…)
The the process is: after starting the app, we receive pushID from apple (or google project), what we store or update in mysql with our name (and other details). We can read the users (list) from mysql,(if we want, we can see only the online users. Any update functions, what are goned over http i found so slowly, so by this reason i use node.js on the server, where we can ‘log in’ if we are online. The difference between other solutions - in this way the client updating his status like online or not. In this way we can send messages for groups, channels, rooms, etc…)
So, when we want to send a message for one user, then we choose him from the list for example. The next api what we call - message sending api. This reveive the ‘from’, ‘to’, and ‘message’ info. First, the api save this message to the database with the from and to details, and with timestamp. Then read the actual pushID of the user (from the database) and send a push message (the database include what type is the phone -ios or android, and use the right message sending process).
In the other side, if the app is not running, or in the background, then a simple push message coming. If the app is runing in the foreground, then we see just a popup, and if we are in the window where we are chatting with the actual user, then we just see a next row with the message.
If we are totally offline (i mean just not running the app), and have the push message, but we’re open the app later, then: the fist is to load unreaded messages. This goes one-by-one (we limited the readable rows from db to 1, and ordered by timestamp). So we just read the message, save locally, and when all is done, we start again the proc… When we receive nil ( zero answer) then the re-reading is stopped.
By this way for me to receive, send, load unreaded messages are fast, simply, and trusty.
If you need any help to build up some similar things, or use one of the services, just let me know, becuse i should need some testers for my other server-api communication services.
Good luck.