Using XMPP to send real-time information to an iOS app

I am developing an iOS application. There are different “areas” in the application, and users can send “things” to them. Other users viewing the same area should have a thing sent to their phone (but only if the application is running).

I started working on Django using the RESTful API. I plan to host a backend on Amazon Web Services and every time something is added to 'area', putting update time and 'area' in the queue using Amazon Simple Queue Service . I'm going to make a Python application that processes items in a queue, querying the database to find out which users have new “things” that they can download - this part is currently planned to send Apple Push Notification to the phone, and if the application works, it can make a simple RESTful request to get new data in JSON format.

However, I believe that XMPP will be a better solution (using XMPPFramework on the iOS side), and this will support Android in the future.


I have done a lot of research on how to use XMPP for this purpose, but the documentation assumes that you will use a public XMPP network so that users have to set up an XMPP account, and it's unclear what chat is.

This project requires the use of XMPP solely to send information from the server to the user device. Thus, it should be a private XMPP network, if necessary, users can be registered for an XMPP account on this private network (but backstage they don’t need to know which technology includes the application.)


Can I use XMPP only to send information to a mobile application? Many of the answers / tutorials on the Internet basically suggest using an XMPP server and client - without mentioning how you can connect them on a private network to send data as defined by something other than the XMPP server.

Thanks for your help in advance :)

+6
source share
1 answer

Yes it is possible. Moreover, you can send and receive anything you want through XMPP.

Typically, XMPP is used for jabber chat accounts. This means a few things.

  • Each user must be configured as a user on the server. This means that the server knows which client needs to embed messages. It's not difficult to just set up a random user / password and associate it directly with the application.

  • The transmission of chat information means that there is a sender and a receiver. In your case, you can probably ignore the sender, but it can be useful if you have several places where messages can come from.

  • The message may contain any required information. I can't remember completely (it's been a while since I used XMPP), but I think you can send XML in the actual message itself (or json or something else), or you can add additional XML to the message and just leave the message itself (or with a nominal value).

What you need to get started is an XMPP server. You can install this on your web server (I assume you can probably install it on AWS, but I'm not sure). This is the server that I always use, Openfire , it is very simple to configure and use (and has a nice web interface that you can use to configure everything). It allows you to send received messages and makes it all "private". This means that although you can connect to jabber public networks, you can also restrict access to the server.

Next you want a web api. There is a good php framework, xmpphp , that will help you configure your api. This api will allow you to send messages from your python script (e.g. post req to curl) to the xmpp server, which will deliver it to the iphone. If you do not want to send messages, then you are all set up. Listening to XMPP messages using php is another fish maker!

Another thing to keep in mind is that you will need to send statuses from the application so that the server knows that you are logged in and “listening” or not. Again, this is all fairly well documented on the Internet if you are looking for it (I cannot remember the exact entries and exits). So, in your python / php script you can check if the user to whom you are trying to send the message is currently "logged in" and "listened". If this is not the case, you will need to implement push notifications and send a push notification. If you are not sure about this, there is a fantastic service called the city ​​airship , which I will recommend. They send up to 100,000 push notifications per month for free (and subsequent notifications are pretty reasonable). Otherwise, be prepared for the fact that the world hurts sets up the service yourself! (I heard!)

I hope I answered most of your questions. Its a rather specialized subject (many people will not know about XMPP - this is one of those things that you only learn about if you need to know about it). XMPP is a very powerful, albeit much better solution than repeating HTTP requests of all kinds. There is a lot of information on the Internet, if you can find it, but you may have to think a little about how to interpret the information, one of those things that has not yet passed to the iPhone in the mainstream (in my opinion).

EDIT ... one more thing

Beware of drops - drops on the Internet, etc. It sounds obvious, but it always bites me! Always forget that sometimes the Internet is disconnected and my XMPP connections need to be reconnected. Esp if people put the application in the background and then come back to it later. :) Remember to reconnect when you need to.

+15
source

Source: https://habr.com/ru/post/904166/


All Articles