Ios development: APNS message push implementation

Source: Internet
Author: User

There are many introductions on the implementation and Principles of the ios message push mechanism (APNS) on the Internet, but they are scattered.
After several attempts, I finally successfully implemented the push process.
Here, I will post my Evernote content, including links to content that will benefit from my own implementation, as well as some issues and solutions.
For the push implementation in php, see another blog: [in writing]

1. How APNS works. configure a developer account to enable the APNS service and obtain the authentication certificate for sending messages. (The link at the end of the article is of poor quality and is not recommended for reading)
 

2. Download the code instance for obtaining tokens on the mobile phone end. [before that, you need to follow the steps above to activate the apns function of appid]
 

Errors occur frequently during implementation:
Error: Error Domain = NSCocoaErrorDomain Code = 3000 UserInfo = 0x1179f0 "the application's" aps-environment "Privilege string is not found"
The reason is that the profile in the project is incorrect.
Solution:
Make sure that you have made the corresponding appid similar to com in the apple dev portal. company. appname (for example, xxxx. * This may cause a matching error.) After activating the pans function, revoke the profile and download and install it to the mobile phone and xcode. (note the following, you must first configure the push function in configure and then download the profile to update the mobile phone and Xcode. If you do not know whether to download or configure first, the most safe way is to first configure, then click modify at profile, change profile to a new name, and install the new profile in the mobile phone and Xcode, so there is no problem)
I spent half a day on this issue. According to my summary after successful implementation, the reason is that there is no clean test environment. If you think that the problem persists after you follow the above steps, it is very likely that you did not follow the above steps completely.

3. Message sending code instance PushMeBaby: [refer to the above steps to generate a key pair on the development machine and obtain the APNS certificate, which is placed in the message sending project]
Remember to replace the. cer file generated when the certificate is created with the project (of course, replace the file name of. cer in the Code ~), Replace the devicetoken in the Code with the token obtained by the mobile phone.

I installed a 64-bit Mount Lion 10.8.2 on my computer. When running the above program, an error is reported:
The run destination My Mac 64-bit is not valid for Running the scheme 'pushmebaba '.
Solution:
Modify the architecture in the PROJECT and target build setting of the PROJECT to 64-bit, the base sdk to 10.8, and run the command again.

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.