APNs Message Push implementation

Source: Internet
Author: User
Tags macbook

Transferred from: http://blog.csdn.net/biaobiaoqi/article/details/8058503

First, the message push principle:

Mention a few of the push-related concepts, such as 1-1, before implementing a message push :

1. Provider: Is the server that provides push for the specified iOS device application (if The iOS device application is a client, then Provider can be understood as the service side [ The originator of the message ]);

2, APNS:Apple push Notification service[Apple message Push server ];

3, the iPhone: Used to receive APNs issued by the news;

4. Client app: Anapp on an iOS device that receives an iphone delivery APNs message to the final responder of a client app[message being developed ];

Can be divided into three stages:

Phase one:provider[service side ] to send the message, the purpose of the iOS device identification Packaging, sent to APNS;

Stage Two: APNs in the list of iOS devices for which youhave registered the push service, look for an iOS device with the appropriate identity and send the message to the iOS device;

Phase three: TheiOS device passes the message sent to the corresponding application and pops up the push notification as set.

Specific processes, such as 1-2:

1, [Client APP] Registration message push;

2, [client app] and [APNS Service] to Devicetoken, client app receive Devicetoken;

3, [Client App] Send devicetoken to [Provider]push server program;

4, when the push server program satisfies the sending message condition,[Provider] sends the message to [APNS service];

5 . [APNS Service] sends the message to the [Client App].

Message Push implementations:

1,     Build Span lang= "en-US" >*.certsigningrequest file , The steps are as follows:

[macbookà application à utility À keychain Access à Certificate assistant à from the certification authority to seek certificates? À certificate information (user e-mail address {fill in your mailbox, such as: [email protected]}, common name { Arbitrary, such as: pushdemo}, the request is: {radio, select ' Save to disk ' }) à continue à save Certificatesigningrequest.certsigningrequest file, named here: pushdemo.certsigningrequest. In this *.certsigningrequest has been generated, the specific operation steps 2-1,

If the build is successful, the [ keychain Access | Login | secret key ] column lists the key associated with *.certsigningrequest , which is Pushdemo, as shown in 2-3:

2. Create a new App ID ( configured in Apple Developer Account )

(1) Log in to iOS Dev Center, and after successful login, click on the (iOS Provisioning portal corresponding link),2-4 as shown:

(2) Create new app Id[app IDsàManageànew app id] (description{fill in your description of this app ID, such as:ishop}, Bundle Seed ID (App ID Prefix) {Select bind app ID prefix, such as: Default selection Generate New},bundle Identifier (App ID Suffix) {fill in bindings App ID suffix, such as:Com.yourcorp.iShop}), as shown in 2-5:

This generates the following record, as shown in2-6:

(3) Configure the APP ID generated in the previous step to support message push [click Configure in 2-6 to select the Enable for Apple push Notification Service à click Configure],2-7 shows :

(4) Generate a Certificate Signing request (Generate deployment requests authentication)[click 2-7 in 2ConfigureàContinueà step 1 generated *certsigningrequest file (here is ishop.certsigningrequest)à Generateà generated after the completion of the download, named: Aps_developer_identity.cer], double-click Aps_developer_identity.cer Certificate {Associate the certificate with the key and import the certificate into the MacBook }, As shown in 2-8:

(5) Create development Provisioning profiles[Development License Profile ] (provisioning| Development| New profile), as shown in the procedure 2-9:

Click Submit in Figure 2-9 to generate the development Provisioning profiles[Development License Profile ], here is: Ishopdevprofile.mobileprovision as shown in 2-10:

Download this development license (for online debugging).

So far, we have generated:A:*. Certsigningrequest file (used in step (4) to generate certificate B),B: Aps_developer_ Identity.cer certificate (used on Provider[push server ] service side),c:*. Mobileprovision Development License Profile (used in the client app app for online debugging).

Code instance download for token on mobile phone "before you do this, you need to activate AppID's APNs function by referring to the steps above."

Http://www.cocoachina.com/bbs/job.php?action-download-pid-tpc-tid-3770-aid-3022.html

Error Summary:

The implementation process, repeatedly encountered error:

Error:error domain=nscocoaerrordomain code=3000 userinfo=0x1179f0 "the right string for the application ' aps-environment ' not Found"

The reason is that the profile in the project is not correct.

Workaround:

Make sure you make the corresponding appid in the Apple dev portal similar to Com.company.appname (if xxxx.* can match errors, etc.), activate the pans function, and then revoke the profile, and download the installation to the mobile phone and Xcode inside (note that you must first configure the push function in configure and then download the profile, update the phone and Xcode, If you do not remember whether it is first download or first configure, then the most safe way is to first configure, and then to the profile there click Modify, the profile changed to a new name, Install the new profile into the phone and Xcode, so there's no problem.)

I spent a large half day on this issue, based on the subsequent success of the summary, because there is no clean test environment. If you feel that you follow the above method, the problem is still, the great possibility is not completely follow the above steps to execute.

3. The code instance of the message sender Pushmebaby: "Need to refer to the above steps, generate key pair in the development machine, and obtain APNs certificate, put in the project of message sending"

Http://dldx.csdn.net/fd.php?i=125637639879612&s=76d8ea9a7077833aaf4aa3c705cdda26

Remember to replace the. cer file that was generated when you made the certificate with the project (of course, replace the file name of the. cer in the code below), and replace the Devicetoken in the code with the token obtained by the previous phone.

The author's computer is mounted on Mount Lion 10.8.2, a 64-bit machine. Run as above program, error:

The Run destination My Mac 64-bit is not valid for Running the scheme ' Pushmebaby '.

Workaround:

Modify the project and Target's build setting in the architecture to 64 bits, and the base SDK to run again after 10.8,clean is OK.

APNs Message Push implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.