http://maxwin.me/blog/?p=170
principle
To put it simply, the app has to dynamically update the message on its own, one of which is polling, which brings additional traffic to the user. Another scenario is for the Push,app client and server to keep a long connection directly, with new messages when the server push to the app client.
Both of these "push" implementations through the app itself are subject to the following issues: The process is shut down and cannot send a request for a large number of apps to open the network connection to the user's traffic and battery will bring a lot of consumption of communication security problems need the app to provide solutions
APNs provides a unified message notification platform for app developers. Keep a long connection between Apple and each iOS device. The developer sends the message to Apns,apns to send the message to the specified iOS device, and the iOS device displays the message and launches the appropriate app.
From the above procedure, to implement message push via APNs, a message needs to identify which app is sent to "which iOS device". These two are identified by the device ID (devicetoken) and the SSL certificate file (an SSL certificate is required to configure an app that opens the message push). The message structure is as follows:
Implementation Scenarios
Detailed procedure please refer to http://mobiforge.com/developing/story/programming-apple-push-notification-services, step by step to be able. This process generates files: Certificatesigningrequest.certsigningrequest is used to generate an intermediate file for the SSL certificate, which can be used to delete the Aps_developer_identity.cer SSL certificate file. This certificate associates the app ID, which can be used to send messages to the corresponding app. [Xxx].mobileprovision and the above SSL certificate file binding app provision file, please install to the test device.
Double-click Aps_developer_identity.cer to import the certificate file into keychain Access.
The SSL certificates and keys required by java/php/c++ are generated as follows: Export aps_developer_identity.cer from keychain access to [XXX].P12 terminal execution:
1 |
OpenSSL pkcs12-in [Xxx].p12-out [Xxx].pem-nodes |
Provide the final generated PEM file to the background server backend code sample
Please refer to the examples in the link above for app client.
Push server:
Object C version Http://stefan.hafeneger.name/download/PushMeBabySource.zip
Java version http://code.google.com/p/javapns/
PHP version http://code.google.com/p/apns-php/
Now the background technology is mainly C/s, the Internet has not found a suitable, their own implementation of the demo, the code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |