IOS development (APNs) remote push implementation code with certificate and real machine debugging
Remote push notification
What is remote push notification
As the name suggests, it is a remote push service for notifications (Networking required) pushed from remote servers to clients, also known as APNs (applepush notification services)
Why do you need remote push notifications? The limitations of traditional data acquisition. As long as users close the app, they can't communicate with the app server and get the latest data content from the server. Remote push notifications can solve the above problems. No matter whether users open or close the app, they just need to connect to the Internet, You can receive the remote notification pushed by the server. Note to users: all Apple devices will establish a long connection with Apple's servers when they are connected to the Internet. What is a long connection? As long as they are connected to the Internet, they will always establish a connection. The action time of the long connection is calibrated. Upgrade the system to find my iPhone The benefits of long connection are fast data transmission speed and the push principle of keeping the data up-to-date
Provider is our company's server. It finds our device through Apple's APNs server and pushes messages to client applications on our device. How does the APNs server find our devices and applications? The answer is devicetoken. Devicetoken can be obtained only by configuring push certificate, The push certificate needs to know our appid (application bundleid, application unique ID) and UDID (device unique ID), as well as the UDID of our own server. Let's type a push certificate, log in to the developer center, and click the certificate module
Click the certificate for IOS apps
Enter such an interface
Click app IDS, and then click the plus sign in the upper right corner
The arrow indicates the application ID description. Let's assume that we have written an awesome application, excetedapp. Next, we fill in the app ID. note that the appid here is fixed and cannot have an asterisk
Next, we add the services required by the app, and then click continue
Click next all the time to finish. Find our excetedapp in the app IDS list. We can see
It is found that the push service is a yellow warning. At this time, click Edit to find the push module. We need to configure the push certificate, and click the position indicated by the red arrow
We need a CSR file. CSR is a signature request file, which means that our MAC has the permission to debug and push. Click continue
Click continue we see
Then we open the keychain on the Mac and request the certificate from the certification authority
Write the first two casually, and finally choose to save to disk
After that, we can add the CSR file
After adding, select generate
The certificate is ready. Download it
It's ready!
By the way, we also matched the issued certificate, and the steps are the same
Open the certificate we just downloaded and add it to the key chain
We can finally start our project. We're crying
Don't forget to modify the bundle ID. you need to get a real machine debugging certificate here
There are not many things about real machine debugging here. After so many things, we can finally get the devicetoken
In appdelegate Register push in M
Devicetoken processing flow
Next, let's test our push with smartpush: https://github.com/shaojiankui/SmartPush