IOS 8 Apple Push Notification Service

Source: Internet
Author: User
Tags ssl certificate ruby on rails

    • Apple Configuration

    • 1. Create Apple ID in Apple Developer Website
    • 2. Check on "Push Notification" in the functionality
    • 3. Configure for Push Notification in Development:create certificate
        • 3.1 Upload the certificate file which is generated by keychain access. 
          • How to generating the Certificate Signing Request (CSR):  
          • 3.1.1 Keychain access, Certificate Assistant, request a CE Rtificate from a certificate Authority
          • 3.1.2 Save the certificate file to the disk as "your Name.certsigningre Quest ", which is used to be uploaded.
        • 3.2 Download SSL Certificate and save as  "Aps_development.cer"
        • 3.3 Click the  "Aps_deve Lopment.cer "To install, you'll see it in keychain access, export as. p12 file
        • 3.4 Use command line to TRANSFO RM it from. P12 to. PEM, which is used in the server. Keep in mind for the password, which would also be used in the server
          • $ OpenSSL pkcs12-in cert.p12-out apple_push_notification.pem-nodes-clcerts
    • 4. Create provision file for the Apple id:generate and drag it to Xcode

    • Xcode Side

In APPDELEGATE.M, implement the methods below:

---------------------------------------------#pragma mark-app delegate//-------------------------------------- --------(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *)        launchoptions {//Override point for customization after application launch. ---------------------------------------------//SET push notification//---------------------------------------- -----if ([Application respondstoselector: @selector (isregisteredforremotenotifications)]) {//IOS 8 Notifica tions [Application registerusernotificationsettings:[uiusernotificationsettings settingsForTypes: ( Uiusernotificationtypesound | Uiusernotificationtypealert |                Uiusernotificationtypebadge) Categories:nil];    [Application registerforremotenotifications]; } else {//IOS < 8 notifications [application Registerforremotenotificationtypes: (Uiremot Enotificationtypebadge | Uiremotenotificationtypealert|    Uiremotenotificationtypesound)]; }//---------------------------------------------//accept push notification when app isn't open//--------- ------------------------------------nsdictionary *remotenotification = [launchoptions objectforkey:    Uiapplicationlaunchoptionsremotenotificationkey];    if (remotenotification) {//[self handleremotenotification:application userinfo:remotenotif];    } else{//Do nothing. } return YES;

---------------------------------------------#pragma mark-push notifications delegate//------------------------ ----------------------(void) application: (uiapplication*) application Didregisterforremotenotificationswithdevicetoken: (nsdata*) devicetoken{NSLog (@ "This device token is:%@",    Devicetoken); NSString *token = [[[[Devicetoken description] Stringbyreplacingoccurrencesofstring: @ "<" withs Tring: @ ""] stringbyreplacingoccurrencesofstring: @ ">" withstring: @ ""] St        Ringbyreplacingoccurrencesofstring: @ "" Withstring: @ ""; Call the server function to register this device//...} -(void) application: (uiapplication*) Application Didfailtoregisterforremotenotificationswitherror: (NSError*) error {NSLog (@ "Failed to get token, error:%@", error);} -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo{NSLog (@ "       Didreceiveremotenotification "); Uiapplicationstate applicationstate = application.applicationstate; if (applicationstate = = uiapplicationstateactive) {//app is already in the foreground NSLog (@ "Content:%                @ ", [[UserInfo Objectforkey: @" APS "] Objectforkey: @" alert "]);        Uiremotenotificationtype enabledtypes = [[UIApplication sharedapplication] enabledremotenotificationtypes]; if (Enabledtypes & Uiremotenotificationtypebadge) {//badge number is enabled} if (enabledty PES & Uiremotenotificationtypesound) {//sound is enabled} if (Enabledtypes & Uiremoteno Tificationtypealert) {//alert msg is enabled}} else{//app were just brought from BACKGR Ound to Foreground}}

    • Server Side (Ruby on Rails):

Gem Recomend:

    • Reference:



IOS 8 Apple Push Notification Service

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: 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.