Can messaging between servers use APNS?

I am working on a messaging application and I have a dilemma on how to send data from server to client.

I use a centralized server design, where clients use NSURLConnection to send messages to the server, the server does not store or manage open sockets and cannot send a message to one of the clients. Thus, clients use a timer and request a server every 2 seconds to see if new data is waiting for them.

The problem with this approach is that polling the server every 2 seconds seems to kill the battery very quickly, so I thought that instead of clients, polling the server, use APNS * , so when the server has some new information ** for the client, the server will send a push notification *** to the client, then the client will retrieve data from the server.

* use APNS - if the client allows this, the client can, of course, disable this option. Therefore, I will check if push is enabled every time the application comes to the forefront, and if not, I will return to the polling method.

** New information can be anything from text messages to server administrator messages. (and there are a lot of admin posts ...)
For example, in my application, users can see the status of their friends (online / offline), therefore, if user1 and user2 are friends, and user2 just changes his status from online to offline, then the server should send this new information (admin message = user2_offline) user 1.

*** Server push push notifications sendings are empty (without data / sound), this is just a trigger for receiving new information, so if a push was sent to the client and the client application was close, it will not notice anything. (if the application is running, it will receive new information from the server)

Will this approach work with a massive messaging application requiring massive use of push notifications?

To be more clear, my main concerns are:
1. Is APNS reliable enough so that I can use it as the primary messaging mechanism between client and server?
2. Will Apple approve potentially thousands or hundreds of thousands of push notifications per day from my server?

+7
source share
2 answers

Is APNS reliable enough to be used as the primary messaging mechanism between clients?

NO . Just to be complete, let me repeat the reasons.

  • Apple itself relinquishes reliability read Programming Guide
  • In addition, APNS has a QoS component that can improve reliability by being in real time (for example, I can ask APNS to provide a notification at any time for 4 weeks and try again if the devices are unavailable), which useful in your case.
  • According to your requirement, if you send a quiet push (push without a message visible to the user), it cannot be sent as a high priority, which further reduces reliability. Here is the corresponding quote

    "Silent notifications are not intended to make your application wake up in the background, and they are not intended for high priority updates. APNs treats silent notifications as a low priority and may if the total number becomes excessive. These limits are dynamic and may vary depending on conditions, but don’t try to send more than a few notifications per hour. "

Will Apple approve potentially thousands or hundreds of thousands of push notifications per day from my server?

Typically, APNS will not have a problem with this in terms of load, but it has throttling in place and they can throttle your notifications, see point 3 above

IMHO, you should look at XMPP, as this protocol is for use only, like yours, and they have broad community support on all platforms. I suggest you look at something like https://github.com/robbiehanson/XMPPFramework and set up an XMPP server on your server that will process messages and message messages as well as admin messages.

If you already rated XMPP and don’t want to go with it, I would suggest you build an intelligent system in an iOS application that uses different strategies based on the state of the application, something like the following, you can have the following strategies

  • Real-time Socket Based Approach -> Establish a permanent connection of sockets and synchronize data as much as possible (this is when your application is running in the foreground or in the background)
  • The polling system that you talked about, what it is about, which can be used when your application is called to update the background sample and location, etc.
  • Use APNS with visible user messages + user data when your server detects that the device does not have an active socket and has not been polled for a very long time.
0
source

I worked in this area for some time, and from my modest experience, I think that your approach to solving your problems will lead to nothing. Let me first highlight some important facts about the characteristics of APN:

  • APNs are not reliable, they are not 100% guaranteed for the client.
  • According to Apple documentation, APNs are the best effort , so they may not reach them.
  • APNs do not store data inside them, so even if they reach your client application, they do not contain anything inside them for the application.
  • APNs are simply notifications to the user that something related to your application has occurred while the message (the text displayed in the APN warning field) is being processed by iOS, and not by your application. That's why devices with iOS 4 will display APN in a different way than devices with iOS 5, this is working with the OS, not your application.
  • The icon icon displayed on your application icon when notifications appear is the responsibility of your server, not the device’s operating system. In other words, when the APN reaches the device, it should appear with a new notification count value for your application. OS will do nothing for this.

Having said that, I would like to explain a little how such applications are usually developed. Firstly, this is not done using URL connections and clients do not check the server every time period. Usually you have a client / server architecture where your client is an application on the device and the server is a real server program that resides on the server machine. The server can be Microsoft (for example, with C #) or MAC (using Objective-C). The server has a database in which information is stored inside it. Some important information (relevant to your question) is the value of the APN Count, the message you want to deliver, the status of the client, if it is online or offline.

When a client likes to send something to another client, or when the server wants to send something to the client (or the entire client), the receiving client is checked whether it is online or offline. If it is online, the message is sent directly, and usually messages are executed on TCP sockets. If the user is disconnected, the server will save the message that needs to be sent to the client, increase the APN Count value, send the APN to this recipient. When this recipient becomes online, the server will notice this (because there is a connection and confirmation of connection) and, therefore, will retrieve all unconfirmed messages from the database and send them to him ...

This is a long process, I hope I could explain something to you a little. In all cases, I do not think that your path is practical or allows you to achieve real work.

-one
source

All Articles