IOS remote notification remote message push processing

There are three scenarios for remote message push processing: app is not running, app is running in the foreground and app is running in the background. The relevant processes and processing steps in the three scenarios are described below

1. Process

(1) Registration notice

The first step is to register remote message push. It should be noted that the registration method has changed in ios8 and later systems (certificate settings and push permissions also need to be enabled). The purpose of this step is to allow apps to receive remote message push.

(2) Bind devicetoken

Devicetoken is equivalent to an ID of the device, and the server pushes messages according to this ID.

① When the user agrees that the app receives the remote message push, the mobile phone will send a request to APNs to obtain the devicetoken;

② APNs receives the request and sends the corresponding devicetoken to the mobile phone according to its corresponding process and algorithm;

③ The mobile phone passes the devicetoken to the app;

④ App then sends the devicetoken to the background server for saving.

In the future, the background server sends push messages to APNs according to the devicetoken, and APNs then pushes the messages to the corresponding devices according to the devicetoken. The devices then evoke the app and display the pushed messages.

(3) Processing for remote push messages

When a remote push message is sent, click to open the message often has some targeted processing or processes. The most common is to jump to the page. It will not be expanded here. The processing steps after receiving the push in different scenarios will be introduced below.

2. Process of pushing messages in different scenarios

(1) App receives push when running in the foreground

The "didreceiveremotenotification" method will be called, and the pushed data is in userinfo for processing.

(2) Receive push when app exits to background status

A notification reminder will appear on the screen. If you click the message to enter the app, the app will call the "didreceiveremotenotification" method when it runs to the foreground, which is why you should distinguish the applicationstate before, because both are processed through this step.

(3) Push received when app is closed or exited

Similarly, a notification reminder appears on the screen. Click the message to enter the app. When starting, the launchoptions corresponding to uiapplicationlaunchoptionsremotenotificationkey in the "didfinishlaunchingwithoptions" method is no longer empty. What it contains is the push content, which can be processed.

3. Others

(1) Remote message push in poor network conditions

If the mobile phone is not on the network, APNs will have a QoS thing to save the message for a short time and push it when the mobile phone is on the network. Of course, the message will not be received after a long offline time, but in practice, it is generally not received when the network seems to be poor.

If the server pushes multiple messages when the mobile phone is offline, only the latest message will be received when the mobile phone is online

(2) Push content format

The pushed content has a fixed format and length, including title (added after ios8.2), body, sound, etc. if the corresponding sound file is not set locally, the value of sound is default, the default prompt tone will sound when the push is received, and the length of the push message is limited to 256 bytes (this limit in ios8 is enlarged to 2KB), For details, refer to the section of the notification payload in the local and remote notification programming guide.

This article has been sorted into IOS push tutorial. You are welcome to learn and read it.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>