I. Principles of message pushing:
1-1:
1,Provider: The server that provides Push for the application on the specified IOS device. (If the application on the IOS device is a client, the Provider can be understood as the server [Message initiator]).
2,APNS: Apple Push Notification Service [Apple message Push server];
3,IPhone: Used to receive messages sent from APNS;
4,Client App: Applications on IOS devices, used to receive messages sent by APNS from the iphone to a developed client app [the final responder of the message];
Provider [server] packs the message to be sent and sends it to APNS with the target IOS device ID;
In the list of IOS devices that have registered the Push Service, APNS searches for IOS devices with corresponding identifiers and sends messages to IOS devices;
The IOS device sends the message to the corresponding application, and a Push notification is displayed according to the settings.
1-2:
1. [Client App] registers for message push;
2. The [Client App] and [APNS Service] require deviceToken, and the Client App receives deviceToken;
3. [Client App] sends the deviceToken to the [Provider] Push server program;
4. When the Push server program meets the message sending conditions, [Provider] sends a message to [APNS Service;
5. [APNS Service] sends messages to [Client App].
Ii. Message push implementation:
1,Generate*. CertSigningRequestFile,The procedure is as follows:
[MacBook-Application-utilities-key string access-certificate assistant-Certificate Authority certification-Certificate Information (User email address {enter your mailbox, e.g.: your@email.com }, common {arbitrary name, such as PushDemo}, request: {single choice, select 'store to disk'})-continue-save], at this time, the specified file will be generated at the place you specified. The default value is CertificateSigningRequest. the certSigningRequest file named PushDemo. certSigningRequest. here *. the certSigningRequest has been generated. The procedure is as follows.
If the generation is successful[Key string access|Login|Key]List and*. CertSigningRequestThe associated key. Here isPushDemo,As shown in:
2,CreateApp ID (Configure in the Apple developer account)
(1) log on. After logging on successfully, click (corresponding link of iOS Provisioning Portal ),:
(2) create a New App ID [App IDs à Manage à New App ID] (Description {enter the Description of this App ID, for example, iShop }, bundle Seed ID (App ID Prefix) {select to bind the App ID Prefix, for example, Generate New} by default, Bundle Identifier (App ID Suffix) {fill in the Suffix of the bound App ID, such: com. yourcorp. iShop}), as shown in:
This will generate the following record, as shown in:
(3) Configure the App ID generated in the previous step to support message Push [Click Configure à in 2-6 to select Enable for Apple Push Notification service à and click Configure].
(4) Generate a Certificate Signing Request (Generate deployment Request authentication) [Click 2Configure à Continue à in step 1 of 2-7 to Generate *CertSigningRequestFile (here is iShop. CertSigningRequest)-Generate-download it after generation, name it: aps_developer.cer], double-click the aps_developer.cer certificate {associate the certificate with the key, and import the certificate to the MacBook }, as shown in:
(5) Create the Development Provisioning Profiles [Development license configuration file] (Provisioning | Development | New Profile). The procedure is as follows:
Submit to generate the Development Provisioning Profiles [Development license configuration file]. Here is: ismo-devprofile. mobileprovision, as shown in:
SummarySo far, we have generated:A:*.CertSigningRequestFile (used in step (4) to generate certificate B),B:Aps_developer_identity.cer certificate (inProvider[Push server] server application), C: * .. mobileprovision development license configuration file (used for online debugging on the Client App Client ).
3,Create a project
AppDelegate. mFile"Didfinishlaunchingwitexceptions"Method, add the following code (Used to push notification feature for app register):
AppDelegate. mAdd the following two methods (Events used to handle register remote notification with device token and register error)
Void) Application :( UIApplication *) application didRegisterForRemoteNotificationsWithDeviceToken :( NSData *) deviceToken
Void) Application :( UIApplication *) application didFailToRegisterForRemoteNotificationsWithError :( NSError *) error
Simulator doesn' t support push notification). Then youA popup window will be displayed on the device (this window will only appear once and the app will not be reinstalled), prompting you That the app will send push notification to you. If you agree, clickOKIf you do not agree, click"Now allow". If OK is selected"Setting> Notifications"Your app will be in the list. In addition, your Xcode output console will display your device token.
5: Export "PushDemo" private key to a ". p12" file(This file will be used when the. p12 or. pem file of apns provider is generated later)
1). right click "PushDemo" private key and select "Export..." PushDemo
2). Save the private key as "PushDemoKey. p12"File, click Save button
3) at this time, you will be asked to enter the password used to encrypt the. p12 file twice, for example, "123321", and then ask you to enter the your mac account password once.
6:"PushDemoKey. p12"Aps_development.cer" file generated by file and step 6 is the source file for APNS provider side, the "cert + key" file used by APNS Provider side to push message is generated through these two files. This Step is used to generate the "cert + key" pem file for APNS provider side (php version.
1)Open Terminal, go to Desktop (assuming the two files are in the desktop)
2)Run the following command to generate the pem file corresponding to the apns cer file"PushDemoCert. pem"
3)Run the following command to generate the pem file corresponding to the private key. p12 file"PushDemoKey. pem"(Note: during the execution, you are required to enter the password set during "PushDemoKey. p12" creation and the password set for "PushDemoKey. pem ".)
4)Run the following commands to combine the cert pem file generated by step 11.2 and the key pem file generated by step 11.3 into a pem file"PushDemoCK. pem"
7:"PushDemoKey. p12"Generated by file and step 6"Aps_development.cer"File is the source file used for APNS provider side. This step is a simple test to test whether the two files are valid.
1)Open Terminal, go to Desktop (assuming the two files are in the desktop)
2) run the following command to test whether to connect the unencrypted data provided by apple (No certificate is required!) APNS server
2195
If you see the following output, your computer can connect APNS. If an error occurs, check whether your firewall allows outgoing connections on port 2195.
Trying 17.172.233.65...
Connected.
Escape character is '^]'.
Press Ctrl + C to close the connection.
3)Run the following command to test whether the encrypted data provided by apple can be connected (Use 2) and 3) to generate 2 pem files!) APNS "sandbox" server for development.
-Cert PushDemoCert. pem-key PushDemoKey. pem
During execution, you are required to enter the password set when PushDemoKey. pem is generated. If the connect server is successful, it will wait for you to enter a string. You can enter any string and press enter to disconnect server. If the connection fails, openssl displays an error message.
Note: There are actually two APNS servers: the "sandbox" server (for testing) the live server (for production mode ). Here we test the sandbox server. The operation of live apns server is similar.
8: Create provider server side (php version)
1). Download SimplePush PHP code to your mac machine and then unzip it.
2). Remove S.ImplePushThe pk. pem in the folder (it is useless), and the step 11.4 is generated"PushDemoCK. pem"CopySimplePushFolder
3). ModifySimplepush. phpThe following lines of file:
4) in the terminal window, go to the simplepush folder and execute the following command. Your iPhone will receive a push message.
NOTE: If your app is running on the iphone and the app is at the front end, it will not appear in the notification area on the top of the iPhone when it receives the push message!
Reference: http://mmz06.blog.163.com/blog/static/121416962011111710934946/
Http://user.qzone.qq.com/75869071/infocenter%23! App = 2 & via = QZ. HashRefresh & pos = 1351564081 #! App = 2 & via = QZ. HashRefresh & pos = 1351564081