Implementation of IOS development app push

Source: Internet
Author: User
Part I.

The first step, of course, is to introduce Apple's push mechanism (PS: In fact, every tutorial has), first of all, look at an Apple's official APNs to explain the outline.

Provider is a server that sends a push message to your mobile phone, and APNs (Apple push Notification Service) is a MAC message Push server. Your local server, when you need to push a message to the application, first send the message to the Apple push server, and then send the message to the phone where the app is installed by the Apple push server.

Let's look at one more illustration:


According to the logic of the above diagram I will explain to you:

1. Your iOS application needs to register the APNS message push function.

2. When the Apple APNs push service receives the registration message from your application, it will return a string of device token to you (very important)

3. Transmit the device token received to your local push server.

4. When you need to push the message for the application, your local push server will send the message and device token to the Apple APNs suit.

5.APNS then push the message to the target iphone


Part II

1. Issuing certificates from a certification authority

Turn on your Mac keychain access: Then click on Keychain Access


It will then pop up a window user email message to fill in the name of your Apple Developer account (should be a mail name), click Save to Disk Selection

Items, click Continue, and display the following:



Click Save, file name: Certificatesigningrequest.certsigningrequest then put him in a folder. Let's name the push.


Part III

Visit Apple Developer URL: https://developer.apple.com/


Select the Membercenter option, go to the landing page, use your Apple Developer account login, and the page will automatically jump to the next image.

Click on the Red selected section for the next action.


Select the Certificates option to set up the certificate, as shown in the figure to explain first:


The development option is used as the name for development use of the certificate, Production option is used to publish products used, the name is very strange is not, the

The previous developer page does not have this option, may be the Apple has changed him, use this name more to let people understand it (literally is the product mody). Two options Live

The steps to enter the certificate are the same, now we use the Developer's option to make the certificate, the following steps: Select the development option:



Click the plus option above,



Select the APNS option (development is certainly in the sandbox environment, simulate the real situation), and then continue



This appid we'll talk about how to build in the next section, now I'm using an application ID that has been generated, and continue continue



This is the choice of the key chain access to download the Certificatesigningrequest.certsigningrequest file, select and generate:


Click Download to get aps_development. cer and save it to the push file.


Part Fourth

Create a new AppID, select the Appids on the page, and then click the "Plus" in the upper-right corner



The app's name is just what Apple wants it to be.



Then Bundleid is more important, in the submission of audits and testing (Apple TestFlight) and pay links need to be used, and just follow the apple requirements to write.



The next step is to choose which services your app needs to use, such as ads, gaming centers, push, pay, and so on.


Finally select the "Submit" option and select the "Done" option in the next interface so that we can set the AppID steps to complete.
Part V: Generating Provisioning Profiles

This configuration profile is divided into two types, one for development use and one for publishing to the App Store.


Create the release version of the Provisioningprofile and the development version of the same process, click Development and then click on the upper right corner of the plus


Will enter the interface of which configuration profile to choose:



We are now testing, so choose the "IOS app Development" option, and in the following distribution release options There are two options, "app Store" and

Ad hoc, you can select the options you want to publish according to the following description. Click Continue to enter the next step.


Select the AppID you created in the previous step and click Continue for next step


Select your developer account and continue for the next step


Select your device in this step (you can only use this signature on the device to debug your device on this step). about how to add your device number

It is also very simple to go in, select "Devices" on the left, then click on the plus sign in the upper right corner to add your device's UUID on the subsequent page (Xcode can be found in the

See) and name (you can take whatever you want to see) then register, follow the process to the last step is completed.

Okay, let's go back to the provisioning profile configuration, and when you've chosen your device, click "Continue" and go to the next page,



Enter a filename (preferably up to understand what is, of course, you can also casually up), click "Generate" into the next page, in this page there will be a next

The Load button lets you download the file, and we download it and put it in the push folder.


part Sixth

Well, the preparatory work has been done, now let's start pushing. (ROAR)

First double-click our generated "aps_development. cer" file, go to keychain access, and find our dedicated secret key (according to the common name that was filled out in the second section from the Certification authority's certificate operation)



I fill in the second part is "Silicon", because of a Mac installed before the No, no screenshots, so casually found a map for everyone to see, with the wisdom of everyone should not be difficult to understand it.

Then right-click the export, and the diagram shown below will pop up.



Store him in the push folder, named "Push.p12," where the export will let you enter the password and verify that you can customize a password, such as abc123

There should now be several files in the Push folder "Aps_development. cer", "PUSH.P12", "Certificatesigningrequest.certsigningrequest", and

The configuration profile that came down just now.


Next we open the terminal to generate the. pem file

1. Generate the. pcm file with the aps_development. cer file, CD to the Push folder



2. push.p12 file as a. pem file


The password entered above is the password that you have set up to export the certificate, that is, abc123. It will then let you enter the password for the. pem file, or use the abc123 to prevent confusion.

So we got two more files in the Push folder, Pushchatcert.pem and Pushchatkey.pem.


3. Merging Pushchatcert.pem and Pushchatkey.pem into a PEM file,



There is another CK.PEM file in the Push folder, and we have all the files we need to use.


The next test, is not very excited ~

In order to test the status of the certificate work, we can use "Telnet gateway.sandbox.push.apple.com 2195" to detect, if the display of the following figure indicates success.



We then use our generated certificate and private key to set up a secure link to link to the Apple server

Enter the following command at the terminal: OpenSSL s_client-connect gateway.sandbox.push.apple.com:2195-cert pushchatcert.pem-key PushChatKey.pem

You need to enter a password (abc123 what we just set).

Then he would return a series of data, and here I would paste a part:


CONNECTED (00000003)

Depth=1/c=us/o=entrust, Inc./ou=www.entrust.net/rpa is incorporated by reference/ou= (C) 2009 Entrust, Inc./CN=Entrust Certification authority-l1c

Verify error:num=20:unable to get local issuer certificate

Verify return:0

---

Certificate chain ... Omitted

。。。。。 Omitted

。。。。。 Omitted

Start time:1416389389

timeout:300 (SEC)

Verify return code:0 (OK)

---

The test is here ...


part Seventh

1. Set up a push project

[OBJC] View plain copy//  //  appdelegate.m  //  testpushnotifiy  //& nbsp; //  created by silicon on 14-10-30.  //   copyright  (c)  2014 year  silicon. All rights reserved.  //      #import   "AppDelegate.h"       @implementation  AppDelegate   @ synthesize mainview = _mainview;     -  (BOOL) application: (UIApplication  *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions   {        if  ([Application respondstoselector: @selector ( isregisteredforremotenotifications)]        {            //IOS8           // Create a uiusernotificationsettings and set the display class type for the message            uiusernotificationsettings *notisettings =  [uiusernotificationsettings settingsfortypes: (uiusernotificationtypebadge |  Uiusernotificationtypealert | uiremotenotificationtypesound)  categories:nil];                       [ application registerusernotificationsettings:notisettings];                   } else{ // ios7            [application registerforremotenotificationtypes: ( uiremotenotificationtypebadge                                         | Uiremotenotificationtypesound                                        | Uiremotenotificationtypealert)];       }               self.window = [[uiwindow&nbs

Related Article

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.