Those things pushed by IOS

Go straight to the topic and talk about how to simulate push and process push messages. Before entering the topic, I'll talk about several key processes: 1. Build push SSL certificate 2. The OS client registers the push function and obtains devicetoken 3. Send push message to APNs with provider 4. The OS client receives and processes the message push flow sent by APNs:

Provider: the server that provides push for the specified IOS device application. If the application of the IOS device is a client, the provider can be understood as the server (the initiator of the push message) APNs: Apple Push Notification service devices: IOS device, which is used to receive the message sent by the APNs. Client app: the application on the IOS device, It is used to receive the message sent by APNs to a specified client app (the final responder of the message). 1. To get the device token, the app must request registration with APNs to realize the push function. After the request is successful, APNs will return a device identifier, that is, devicetoken, to the app. When pushing the notification, the server needs to specify the devicetoken of the push notification destination device. In IOS 8 and beyond, registering push services is mainly divided into four steps:

The API registered in the first step above is new to IOS 8. Therefore, in IOS 7, the first two steps need to be changed to the API in IOS 7. The devicetoken may change, so you need to register and upload it to your server every time the program starts.

2. Processing push message 1), the program is not started, and the user receives the message. You need to get the message content in the didfinishlaunchingwithoptions in appdelegate

2) . when the program runs in the foreground, there will be no message prompt (prompt box or banner) when it receives a message. When the program runs in the background, there will be a message prompt when it receives a message. Click the message to enter the program. The didreceiveremotenotification function of appdelegate will be called, and the message will be passed in as a parameter of this function

3. You can add a custom prompt sound file to the app bundle. Then, when the notification arrives, you can specify to play the file. Must be in the following data formats:

You can package them as AIFF, WAV, or caf files. The customized sound file time must be less than 30 seconds. If it exceeds this time, it will be replaced by the system sound. 4. Payload payload is a part of the notification. Each push notification contains a payload. It includes the way that the system reminds users of arrival notification, and you can also add custom data. That is, the main data transmitted by the notification is payload. Payload itself is a string in JSON format. It must contain a dictionary with APS key. APS can contain one or more of the following fields: Alert: its content can be a string or dictionary. If it is a string, this content will be displayed in the notification. Badge: its value is a number, indicating how many corner marks the application will change when the notification reaches the device. If this field is not used, the applied corner mark will not change. When set to 0, the applied corner marker is cleared. Sound: Specifies the file name of the reminder sound accompanying the display of the notification. If the specified file cannot be found or the value is default, the default system sound will be used. If empty, there will be no sound. Content available: this field is used by IOS 7 silent remote notification. You do not need to include this field when you do not use this feature. If you need to add custom fields, let the partners of the server add an array at the same level as APS (take Jason as an example):

In this way, a server field will be added to the received payload. 5. In the background server commonly used for simulation push, the push certificate and the private key of the push certificate are generally exported p12 to the background personnel. Generate the PEM certificate required for PHP. 6. PHP is a little naughty and needs to be converted into PEM. Preparation: 1) the certificate side of Apple server is set correctly! The packing certificate and description file are correct!! 2) Download the push Certificate (CER format) and import Keychain to ensure that the private key exists and does not exist. Go to the computer that created the certificate and ask for a copy. 3) The ~ ~ root certificate ~ ~ (push certificate) private key (p12 format) exported from the key store step 3: the private key of the root certificate here is a pit! Because the creation of an app's push certificate can be different from the computer created by the root certificate, that is, the certsigningrequest generated by Keychain is different, so the private key is also different. When generating PEM here, pay attention to using the private key of the push certificate! Operation process: A. convert the push Certificate (. CER) to PEM file, execute the command: OpenSSL x509 - in push certificate Cer - Information der - out push certificate PEM B. convert the private key (. P12) file exported from the push certificate into PEM file: OpenSSL pkcs12 - nocerts - out push certificate private key PEM - in push certificate private key P12 C. regenerate the generated two PEM files into a PEM file to integrate the certificate and private key into one file: cat push certificate PEM pushes the certificate private key pem >PHPPush. PEM then put this phppush PEM to the backstage friends, you can get off work. Of course, testing push is also troublesome. You need to simulate the real push environment and generally need help from the background. However, when you meet some background colleagues, they strongly believe in the chain and despise IOS. They have called you "pre death" for many years, and there are so many things... So there are two ways to realize self push about debugging push! Don't bother others. Analog push: push through the terminal

Copy the above code and save it as push PHP then generates a push according to the above steps to generate the PEM certificate required by PHP Put the two PEM files in the same directory and execute the following command

The result is

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
分享
二维码
< <上一篇
下一篇>>