Detailed explanation of ios10 push tutorial

Last month, I received a request to push ios10 with the intention of hitting the headlines of the app store I was so crazy that I didn't have any tools, so I quickly installed Xcode beta and ios10 beta, and then began to check the data endlessly. After all, I haven't done any new functions after all Fortunately, I rushed out before the press conference. Because I was lazy, I didn't write it until now. Next is the moment to witness miracles!

principle

In the figure, provider refers to the push server of an iPhone software, which I will use in this article Net as a provider.

APNs is the abbreviation of Apple Push Notification Service (Apple push server), which is Apple's server.

The above figure can be divided into three stages.

Phase I: Net application packages the message to be sent and the identity of the destination iPhone and sends it to APNs.

Stage 2: APNs finds the iPhone with corresponding identification in the iPhone list of its registered push service, and sends the message to iPhone.

The third stage: the iPhone passes the message to the corresponding application, and pops up the push notification according to the settings.

We can see from the above figure.

1. The first is the application registration message push.

2. IOS and APNs server need devicetoken. The application accepts the devicetoken.

3. The application sends the devicetoken to the push server.

4. The server program sends a message to the APNs service.

5. The APNs service sends messages to the iPhone app.

After Xcode 8, the test environment certificate can be generated automatically, so I won't say more

establish

I wrote the today extension of ios9 a long time ago. Similarly, I need to create a target,

As shown in the figure, notification content is responsible for customizing the notification UI, and notification service extension is responsible for receiving and processing data

The extended class of Zhenghuo IOS can't request data on the Internet independently, but I checked some other apps during today. When I pulled down the notification bar, some apps can catch packets. It's estimated that a separate package of network requests is made. It's just a blind guess. If there are similarities, it's a coincidence But the notice doesn't have to be so troublesome First, select a picture from the Internet (limited to HTTPS protocol): https://homeba.s3.amazonaws.com/__sized__/scene/2c0f3bdb7715fed7190fd87e5e5340e4-1473387950-crop-c0-5__0-5-590x442-85.jpg , push format and can be selected. For details, see: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html .

The above figure is the format I use. IOS will automatically obtain and classify the internal content of "APS"

Alert is the text content of the notification,

Sound is the notification sound, which is the default,

Whether badge displays the program badge,

The key point is mutable content, which determines to call the custom notification interface, that is, notification content controller

Category is a value negotiated with the background to display action, that is, to notify the button below. You can expand some operations without entering the program

Some required fields can be added outside "APS", depending on the specific requirements

The preparation of the push tool has been completed. Let's start the code dry goods

Because it is not convenient to use the sdimage framework, the network request can only let go and have plenty of food and clothing. In addition, although the ios10 notification can load pictures, it can only load local pictures. Therefore, a process needs to be done here. First, the picture request can be saved to the local location

Then the data convenience has been completed. The last step is to customize the UI and obtain pictures The built-in storyboard is still very easy to use

Good constraints can add pictures!

It's that simple, it's done!!! (sighs of relief......)

A rendering, ha ha

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