In the era of mobile Internet, news push is a high-quality and cheap channel to run an APP well. In simple terms, the usage scenarios of message push can include the operation type of message push, such as the push during activity promotion, and the notification type of message push, such as the new message reminder in the social scene.

For APP, message push can play the role of informing content, improving daily life, and even recalling users. So how to access the third-party push platform? In this article, senior R&D engineer of netease Yunxin will talk with you about the technical solutions of accessing various third-party push platforms and share some practical experience of accessing push platforms.

How to access third-party push

1. General process of push

Push is a behavior in which the server actively pushes messages to the device and therefore depends on the long connection between the device and the server. The overall architecture and process are as follows:



Details are as follows:

1) Establish a long connection between the device and the push server

2) The device will generate or obtain a DeviceToken from the push server according to some rules, and the push server can locate the specific device according to the DeviceToken

3) The device reports DeviceToken to the application server (completed by the application itself)

4) The application server invokes the server interface of push to initiate push as required

5) After receiving the push request, the push server locates the specific device according to the DeviceToken in the request and delivers the push notification

6) After receiving the push message, the device can perform pop-ups in the notification bar or other behaviors

2. iOS

Apple officially provides APNS push, which has a high push delivery rate. The previous APNS push provides a set of interface based on TCP protocol, but the interface is complicated to use. A slight error will lead to push failure, but the caller still mistakenly thinks that push success.

Apple has since added a new http2-based interface that can track whether each push request was rejected or accepted by the APNS server, eliminating the need to guess whether the request was dropped or accepted by the Apple server.

3. The android

Google officially provided GCM push at the first time, and later launched FCM push to replace GCM. However, since the domestic environment is not suitable for use, various mobile phone manufacturers have launched their own push. The principle of push is similar, relying on the long connection between the device and push server. But the manufacturer can push the advantage of such a long connection and their mobile phone system together, allowing different applications to share the same long connection, save the heartbeat traffic consumption, and the system level long connection don’t have to worry about were killed as a result of application in long connection broken even lead to being pushed inaccessible.

At present, manufacturers have launched the push, including Xiaomi, Huawei, Meizu, OPPO, etc. FCM can also be considered as the system level push of devices installed with Google services.

Different from IOS, android push server interfaces are HTTPS interfaces, and security verification is performed by SecretKey.

A little experience

1. Manage DeviceToken

We know that DeviceToken identifies A specific device, but the push service itself does not know the account system of the application itself. Therefore, if the same APP logs out of account A and uses account B to log in, then DeviceToken generally remains unchanged. In this case, the application server needs to mark that the device of account A is in the deregistration state; otherwise, account B will receive A push message for account A.

2. The application is uninstalled

When the application is uninstalled (account A is logged in to at this time), the application itself cannot sense that the device push for account A will still be sent. The push server receives the push message and cannot find the corresponding device. There is no problem in this case, but some resources will be consumed. Assume that the application on the device is reinstalled and another account B is logged in. Assuming that the DeviceToken does not change, the push for account A will be received by account B. The precondition for the occurrence of the above situation is that DeviceToken has not changed. The test found that huawei push has this problem (after inquiring Huawei push technical support, the problem does not exist on devices after March 2018), and other push does not. To solve this problem, the server must manage the DeviceToken-user account mapping itself and set the old account to logout if a DeviceToken conflict is detected.

3. Problem with push timing in IM scenarios

In the IM scenario, the application server has its own long-link service. In this case, the third-party push service uses the system hierarchy connection pushed by third-party vendors to improve the message push delivery rate.

First of all, for the IOS terminal, the application cannot stay in the background. We will send a marker bit through IM long connection before the application switches to the background. The server will trigger APNS push when the device is offline or in the background, so as to reduce the traffic consumption of APNS push when the device is in the foreground.

For Android, the server will trigger the third-party push when the device is offline, otherwise it will send notification through IM long connection. When the device is in the background but still alive, it will actively pop up the window after receiving the message to remind the user of the new message. Another scenario for Android is that an Android process dies in the background at some point, a message comes in that needs to be pushed, and the server finds that the device is offline and tries to invoke a third-party push (which may or may not be available). After a while, the process reconnects to the IM server and receives the unread message. In this case, the process automatically pops up to inform of the arrival of the message, resulting in two notifications in the notification bar of the device. To solve this problem, the IM server needs to send the message whether unread messages need to pop up when the device is reconnected.


The above is the introduction and experience sharing of netease yunxin’s technical solutions for third-party push platform. For more technical dry products and practical experience sharing, please pay attention to the blog of netease Yunxin.