IOS Remote notification detailed

Source: Internet
Author: User
Tags pkcs12

First, create a certificate

1 Click the key icon

2 in the menu bar, select: Keychain Access? Preferences? certificate tab, the following two items all select Close

3 Generating a certificate request: Keychain Access? Certificate Assistant request a certificate from a certification authority



4 Enter two e-mail addresses and a common name. The email address is your registered AppleID.

A) Common name enter the name you registered on the Apple website, other names have not tried, do not know the line.

b) Select "Save to Disk". The saved name should be: Certificatesigningrequest.certsigningrequest

c) after saving to disk in your Keychain Access window you should have two keys, a public key, a private key, and the red part is the common name you entered above.

Ii. Certificate of Generation

1, on the Apple Developer's website to enter the following page, is Certificates,identifiers&profiles block, followed by a link (https://developer.apple.com/account/ios/ Certificate/certificatelist.action)

After clicking Add, select iOS development, and then let you select a. certsigningrequest file (the one that was just generated). When you are finished, you will generate a developer certificate. cer file, download it to your Mac computer, and double-click Install.

OpenSSL pkcs12-in certificatename.p12-out certificatename.pem-nodes

Third, apply for app IDS on the developer's website

1, the top one is done, this is easier. Note that the bundle ID is set to be consistent with the bundle Identifiler of your app project, naming the specification "COM. Name of the team."

Below I chose the wildcard app Id,explicit app ID should also be possible

Principle: This is how many app IDs you need to apply to the app you're currently developing

Iv. apply for Devices authorization on the developer's website

1,name is the name of the owner of your device.

2,udid is the ID of your device, very long. Teach you a way to plug in a data cable on your Mac, open Xcode, go into window/devices, you can see identifier, copy, and paste the past.

Principle: is to add testable equipment, there are several devices, how many times to add

Five. Generate a description profile on the developer's website. mobileprovision file

1, the front is finished, this is not much to say, the operation is similar. is to select the CER, select the app ID, and select devices. This step is the operation of connecting your mac,app,iphone.

When you are finished, download and double-click Install.

Six, start configuring Xcode (3 places)

1, configure the bundle Identifier, with the developer official website set up the app IDs Identifier consistent (just said once)

2, configure Code Signing Identity, set debug for iphone Developer

3, in the upper left corner of the simulator to replace the real machine, and then run, you can see the results

Above is the method of creating the certificate. Reference: http://www.cnblogs.com/MartinLi841538513/articles/3831726.html/http://blog.csdn.net/quanqinyang/article/ details/21695323

Let's start our push route.

1, first to developer.apple.com up to download their own created push certificate, certificate column. Download APNs certificate (divided into development and production), download the development of the certificate can be, the app on-line after the service side of the certificate to production on it. Clicking on the downloaded certificate will appear in the keychain.

Generate the. p12 file as


Generate a certificate in PEM format

Open the terminal and enter the directory where you saved the. p12 file

OpenSSL pkcs12-in certificatename.p12-out certificatename.pem-nodes

So you'll see a. pem file, developing and producing the same way

2. Set up the certificate in Xcode, and set the development certificate in Code signing in order to receive the notification message sent by the server.

3. Configure the client's code in the APPDELEGATE.M file:

Registering Remote notification types

-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{if ([[[UIDevi] Ce Currentdevice] systemversion] floatvalue] >= 8.0) {[[UIApplication sharedapplication] Registerusernotific Ationsettings:[uiusernotificationsettings Sett Ingsfortypes: (Uiusernotificationtypesound | Uiusernotificationtypealert |         Uiusernotificationtypebadge) Categories:nil];    [[UIApplication sharedapplication] registerforremotenotifications]; } else {[[UIApplication sharedapplication] Registerforremotenotificationtypes: (uiremotenotification Typebadge | Uiremotenotificationtypesound |    Uiremotenotificationtypealert)]; }}

Implementing a Delegate method

<span style= "color: #333333;" >-(void) application: (uiapplication*) Application Didregisterforremotenotificationswithdevicetoken: (NSData*) devicetoken{    NSString *tokenstring = [[Devicetoken description] stringbytrimmingcharactersinset:[ Nscharacterset charactersetwithcharactersinstring:@ "<>"] stringbyreplacingoccurrencesofstring:@ "" withstring:@ ""];    Registering with your own server Devicetoken    }</span>

Failure callback method

<span style= "color: #333333;" >-(void) application: (uiapplication*) Application Didfailtoregisterforremotenotificationswitherror: (NSError*) error{    NSLog (@ "Failed to get device token, error:%@", error);} </span>

How to handle receiving remote notifications

< Span style= "LINE-HEIGHT:19.5PX; Font-family:verdana,geneva,arial,helvetica,sans-serif; font-size:13px ">

<span style= "color: #333333;" >-(void) application: (uiapplication*) Application didreceiveremotenotification: (nsdictionary *) userInfo{    // Here you can make some page jumps according to the content of UserInfo, maximum 256 bytes    }</span>
ways to clear notifications:

[UIApplication sharedapplication].applicationiconbadgenumber = 0;

[[UIApplication sharedapplication] cancelalllocalnotifications];

Put in different methods according to the project requirements.

applicationdidbecomeactive and didfinishlaunchingwithoptions

iOS8 the following remote notification does not support a single purge in the notification bar, local notifications support a single purge

-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification*) notification{    [[UIApplication sharedapplication] cancellocalnotification:notification];    }

There are many new features in iOS8, which will be introduced later.









IOS Remote notification detailed

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.