I. Principles of message pushing:
Before implementing message push, we should first mention several push-related concepts, such:
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: the app on the IOS device. It is used to receive messages sent from the iphone to a Client App [the final responder of the message].
There are three phases:
Phase 1: Provider [server] packs the message to be sent, and sends the ID of the target IOS device to APNS;
Phase 2: APNS searches for IOS devices with corresponding identifiers in the list of IOS devices that have registered the Push Service, and sends messages to IOS devices;
Phase 3: The IOS device transmits the sent message to the corresponding application, and the Push notification is displayed according to the settings.
Specific process, such:
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 the *. certSigningRequest file as follows:
[MacBook à app? utility? Key string access? certificate assistant? À Certificate Information (User email address {enter your mailbox, such as: your@email.com}, commonly used name {arbitrary, such as: PushDemo}, request is: {single answer, select 'store to disk'}) à save]. 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 shown in the following two figures.
If the key is successfully generated, the keys associated with *. certSigningRequest are listed in the [key string access | login | key] column, as shown in PushDemo:
2. Create an App ID (configured in the Apple developer account)
(1) log on to the iOS Dev Center. After Successful Logon, click (corresponding link of the iOS Provisioning Portal), as shown in:
(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:
The following record is generated, 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], as shown in:
(4) Generate a Certificate Signing Request (Generate deployment Request authentication) [click the * certSigningRequest file generated in step 1 of 2Configure à Continue. (here it is iShop. certSigningRequest) à Generate à after the generation is complete, download it, name it: aps_developer_identity.cer], double-click the aps_developer_identity.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:
Click Submit in to generate the Development Provisioning Profiles [Development license configuration file]. Here is: isw.devprofile. mobileprovision, as shown in:
Download this development license for online debugging ).
To sum up, we have generated: :*. certSigningRequest file (used in step (4) to generate certificate B), B: aps_developer_identity.cer certificate (used in Provider [Push server] server application), C :*.. mobileprovision development license configuration file (used for online debugging on the Client App Client ).
So far, the configuration of message Push has been completed, and the next task is to write the programs of Provider [Push server] server application and Client App Client application.
3. Provider server implementation
Here is a brief description of the Provider server (JAVA implementation) steps as follows:
(1) Create the *. p12 file required by the Provider Server:
The key and certificate shown in the figure in Section (4) of the preceding implementation are not used. Why do we need to display the key and certificate? *. P12 file? Haha, you guessed it. Next we will use it to create *. p12 file, step: ([MacBook à à key string access [key string: Login, type: Certificate] à select the certificate just generated (Apple Development IOS Services: * ******) à Menu à file à export project... À [storage: any file name (such as iPush), file format: default (Personal Information Exchange (. (p12)] (enter the password to export [Password: arbitrary, verification: The same as the password] (enter the MACOs logon password) (allow.
Key steps are as follows:
(2) Compile the key code of the Client App Client as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
ApplicationUIApplicationapplication didfinishlaunchingwitexceptionslaunchoptions
Self. window UIWindow alloc initWithFrameUIScreen mainScreenbounds autorelease; Self. window. backgroundColor UIColor whiteColor; Self. window makeKeyAndVisible;
UIRemoteNotificationType types UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert;
UIApplication sharedApplicationregisterForRemoteNotificationTypestypes; ;
ApplicationUIApplicationapplication DidRegisterForRemoteNotificationsWithDeviceTokendeviceToken
NSLog, deviceToken;
ApplicationUIApplicationapplication DidFailToRegisterForRemoteNotificationsWithErrorerror
NSLog, errorlocalizedDescription;
ApplicationUIApplicationapplication DidReceiveRemoteNotificationuserInfo
NSLog, userInfo; UIAlertView alert UIAlertView alloc initWithTitle Message Delegate CancelButtonTitle OtherButtonTitles; Alert show; Alert release;
|
(3) write the key code of the Provider server, as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
MainSend
Main args
DeviceToken .. DeviceToken
PayLoad payLoad PayLoad PayLoad. PayLoad. PayLoad.
PushNotificationManager pushManager PushNotificationManager. PushManager., deviceToken
Host Port Path CertificatePath path
CertificatePassword PushManager. host, port, certificatePath, certificatePassword, SSLConnectionHelper.
Device client pushManager. PushManager. client, payLoad
PushManager.
PushManager. ..
Ex
Ex.
|
Note: If the Provider server is implemented in Objective-C, the *. p12 certificate is not required.