Push technology in Android, iOS, and Windows Phone

Source: Internet
Author: User

Transferred from Li Ning's blog: http://blog.csdn.net/nokiaguy/article/details/11175359

Push is not a new technology, which is already popular in the internet age. But with the advent of the mobile internet era, push technology is becoming even more important. Because in a smartphone, push can in some way replace text messages that have been used for years, and can show users more information (like, tables, sounds, and so on) than text messages.

The implementation of push technology typically uses the way the server pushes messages to clients. This means that after the client registers with the server through the username, key and other IDs, the message can be sent to all active clients on the server side.

In fact, in many mobile operating systems, the authorities have provided them with push schemes, such as Google's cloud push, IOS, and Windows PHONE7/8, which also offer similar push scenarios. However, these push programs in the server are abroad, some push services (such as Google's cloud push) in the country for some reason is not too stable, so in recent years, the emergence of a lot of special for the Chinese people to build a push service.

This article will introduce the various implementation methods of push technology from various popular mobile operating systems. Of course, our main goal is to discuss Android's push technology.

First, the push technology of iOS

Apple offers the perfect push for iOS, with the rationale that Apple has its own push server called APNs (Apple push Notification Service, Apple push Notification server). The client device (IPhone, ipad, etc.) establishes a long connection directly to the APNs. However, the messages sent to the client device are not generated by APNs, but are generated in the server (known as provider) that the user needs to send the message to, and then the provider sends the message to APNs, and finally the message is sent to the client device by APNs. That is, the message is initially generated by provider, and then provider sends the message to APNs, which is then transmitted to the client device by APNs. Message delivery is shown in procedure 1.

Figure 1

The delivery of this token is always accompanied by the sending of a message to the client device receiving the message. To use APNs to provide a messaging service, the application needs to provide a necessary information for iOS registration that is related to the current device Token,ios after receiving Devicetoken, the device will be queried APNs Token is registered on the APNs (all iOS devices need to register an account with the Apple server for the first time, otherwise they cannot download the app from Applestore, and of course the push service is not available), if they have already registered, APNs will return this devicetoken directly to the application. After the application obtains this devicetoken, it means that APNs has allowed to push messages to itself, and then it needs to send the device token to the push server (Provider). Here the application has successfully registered itself in the APNs. You can now generate a message to push through provider, and then provider sends the message to the APNS server, and the APNS server will send the message directly to the application. The process is complicated, but looking at the 12 description will get a better understanding of the process. Each process describes the order in which the preceding number represents the time of dispatch.

Figure 2

Second, the Windows phone push technology

Microsoft's push for window phone is similar to iOS, and it also needs to prepare its own push server (which can be called a cloud Service). Simply means that the device's ID becomes a URI. There is a push Client Service (PCS) in the window phone. All applications that require push services need to communicate with the push Client service. Here are the basic steps of the window phone push, which the reader can look at in contrast to Figure 3.

1th Step : The application will request a push Notification URI (①) to the push Client service.

2nd Step : If the current window phone device is already registered with Microsoft server, the push Client service will be from MPNs (Microsoft Push Notification Service, Microsoft Push Notification Service) Gets the push Notification URI and returns it to the application, which indicates that the push service is available (② and ③).

3rd Step : The application needs to send the push Notification URI to its own push server (Cloud Service) (④).

4th Step : If you need to push a message, Cloud Service sends the message to MPNs, then MPNs will send the message to the push client service, and finally the message will be delivered to the application by the Push client service (⑤, ⑥ and ③).

Figure 3

Third, the Android push program

Android's push scheme is more and more chaotic. For example, there are Google's official C2DM (Android Cloud to Device Messaging), third-party push services (such as Aurora Push), and push service-side programs (such as ANDROIDPN) implemented through various protocols, Users can build their own push servers through these service-side programs. These push techniques are detailed in the sections later in this section, and this section first describes the various push technologies that are used frequently in Android. Of course, these push technologies can also be used for other mobile devices, but because Android's official push service (C2DM) has some problems in domestic use, Android-based third-party push services are more than other systems, so this is mainly for Android.

Typically, push technology is implemented in the following two ways.

1. Polling (pull) mode

2. Persistent connection method (service side push mode)

Polling means that the client constantly queries the server for new messages at a certain interval. This way, you must implement the communication mechanism with the server, such as Message Queuing. and also consider the frequency of polling, if too slow can cause some message delay, if too fast, it will consume a lot of network bandwidth and battery. Therefore, most push services do not use polling methods.

Persistent connection mode is the push mode, for the client, is a passive way, and the initiative on the service side, when there is a message, the server will be registered to all the push servers Client push messages. The advantage of this push method is that it guarantees real-time, and the client implementation is simple. Of course, there are also deficiencies, for example, if a large number of clients keep a long connection with the server, they consume the resources of the servers. However, when messages are not pushed, these long connections become idle connections, which typically consume memory resources primarily. For example, 2 million users may consume dozens of GB of memory. So when you build this push mechanism, use a server with good performance.

There are many ways to implement a persistent connection, for example, you can use XMPP as the communication protocol. The main advantage of XMPP is that the protocol is mature, strong and extensible. XMPP is more used in IM systems, and the following ANDROIDPN is also used with the XMPP protocol.

XMPP also has obvious drawbacks, such as the complexity of the protocol, if the thoroughly understand XMPP protocol may take a long time, and because XMPP is XML-based, resulting in data redundancy, which can cause mobile device fee flow, power consumption and other ills.

In addition to XMPP, you can also use the MQTT protocol, the main advantage of this protocol is simple, small, extensible, resulting in the advantages of saving traffic, power saving, and the C + + version of the service-side component RSMB. The disadvantage is that the protocol is not mature enough, and the implementation is more complex, and RSMB is not open source, the cost of deploying hardware is higher.

Although C2DM services may not be stable at home or some areas are not available, it is necessary to introduce the principle of C2DM. However, for domestic applications, it is best to use a third-party push service, or assume that you are pushing the server.

C2DM and iOS APNs and window phone's MPNs are similar. You also need to prepare a push server yourself, and the following steps to implement the message push.

1th Step : The C2DM service on the mobile device needs to interact with Google's official C2DM server to verify that the current device is registered on the C2DM server, and if it is already registered, the C2DM server returns a registration ID to the client's C2DM service. (① and ②)

2nd Step : The client's C2DM service interacts with its own push server, passing the login ID and the registered IDs returned by the C2DM server to the push server. (③)

3rd Step : If you want to push a message, the push server sends the registration ID and the message to be pushed to the C2DM server first, and then the C2DM server pushes the message directly to the client (phone, tablet device) (④ and ⑤).

Readers can understand these 3 steps against figure 4来.

Figure 4

In addition to the use of the official push program, the domestic emergence of a number of third-party push programs, such as the Aurora Push (Jpush), Baidu Push and so on. Readers can also use them, which are usually free (there may be a charge for pushing multimedia data).

Push technology in Android, iOS, and Windows Phone

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.