How messages are processed in iOS instant Messaging

Source: Internet
Author: User

Usually we do a timely communication of the message, are the use of the socket, the reason is many, the most important thing is that the socket can be actively pushed by the server message to the client.

We all know that in iOS, our app can be switched to the background, when our app is switched to the background, the official saying is that can give us 300 seconds to deal with some things from the foreground into the backstage, but not necessarily 300 seconds, if the memory is tight when the situation, Will be ruthlessly killed by the operating system.


Usually the client-to-server connection method is usually through the heartbeat packet maintenance socket connection, when our app is switched to the background, if the connection is continuous, then we can theoretically use the connection, but when the server pushes the message to the client, how should we display it?


When I was doing this, I used 2 different ways to deal with it:

1, when I entered the background, I entered the background state, tell the server, let the server push the message to the client (APNS), so that the message can be displayed on the desktop, but this way the message is often slow to reflect. Let's just imagine how users will use our software.

The steps should look like this: Open the app----> Chat-------> Cut to the front desk------> receive a message--------> open the app to chat, and then after discussion we used the 2nd way.

2, Online mode server push message.

In fact, when our app is in the background, and the socket is alive, the socket message, using the timer, simulates the way the operating system (analog APNs), sends the display to the desktop.


The approximate flowchart is as follows:



How messages are processed in iOS instant Messaging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.