IOS Remote Push Notification detailed

Source: Internet
Author: User
Tags notification center

1:ios local notifications and remote notifications

http://wangjun.easymorse.com/?p=1482

2: Apple remote Notification Service Request activation example (foreign Guy wrote.)

Http://mobiforge.com/developing/story/programming-apple-push-notification-services

3: Book reference: IPhone Development Cheats 16th Chapter push notifications.

Okay, get into the text:

The first is the URL for the certificate.

Https://developer.apple.com/ios/manage/overview/index.action

After the login is successful, go to the main page of iOS configuration management.

The first step is to create a new App when the IDs are created successfully, you will need to provide a security certificate to excite the push service, such as:

After selecting save to disk, generate a file name (CSR): certificatesigningrequest.certsigningrequest

Go back to the Apple page to submit this and prompt for excitement.

After the successful activation of the App IDs to download the development version or release of the active push Certificate (aps_development.cer), if you need to do a server proactive push, you have to download this file to use the push service.

The second step is to provide the app with a certificate to accept the push license, click Provisioning to set it up, add a new license, and select the app IDs that you just created. Then select the iphone device that you can debug.

Finally, the same is downloaded: ysypushmessagedemo.mobileprovision Double-click the certificate and let it load once.

Next, go to iOS Engineering and select Use this certificate to debug.

In the red circle, all the license certificates that were just loaded are set.

So here, the preparations for the certificate class are all ready.

Here again this emphasizes the specific role of each file

1:certificatesigningrequest.certsigningrequest: Used to generate app IDs

2:aps_development.cer certificates used to develop proactive push services

3:ysypushmessagedemo.mobileprovision License Service to accept push notifications for apps

For unsolicited push code and use, please refer to the first blog post at the beginning

This is only attached: Https://github.com/stefanhafeneger/PushMeBaby

Next, talk about receiving the push notification code aspect.

1: The app needs to accept the push message from the service provider,

[CSharp]View Plaincopy
    1. [[UIApplication Sharedapplication] registerforremotenotificationtypes: (Uiremotenotificationtypebadge | Uiremotenotificationtypesound | Uiremotenotificationtypealert)];


2: After the application is issued, if successful, the delegate will automatically return a device token (token), if it fails, it will enter another failed delegate

[CSharp]View Plaincopy
  1. Remote Notification Registration Successful delegation
  2. -(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken
  3. {
  4. NSLog (@"%@", Devicetoken);
  5. Self.viewController.toKenValueTextView.text = [NSString stringwithformat:@"%@", Devicetoken];
  6. Self.viewController.pushStatusLabel.text = @"already registered.";
  7. }
  8. Remote Notification registration failed delegation
  9. -(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error
  10. {
  11. Self.viewController.toKenValueTextView.text = [error description];
  12. }


3: Provide the device token code to the service provider for push to the specific phone. If a remote push message comes, the user taps the push message, or the app is already open, the system automatically calls the following delegate:

[CSharp]View Plaincopy
    1. Delegate that is called when a remote notification is clicked if the interface is open, the delegate responds directly to the
    2. -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo
    3. {
    4. NSLog (@"remote Notification");
    5. [Self pmd_uespushmessage:userinfo];
    6. }


4: The 3rd inside the situation is that the application is already running, the above delegate will be executed, if the application is not enabled, and then need to respond to the message, then the following delegate processing is required.

[CSharp]View Plaincopy
    1. -  (BOOL) Application: (uiapplication *) application  Didfinishlaunchingwithoptions: (nsdictionary *) launchoptions  
    2. {  
    3.     //here processes the application if it is not started, but is opened by a notification message, you can get to the message at this time .  
    4.     if  (launchoptions != nil)  {   
    5.         nsdictionary * userinfo = [launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey];   
    6.         [self PMD_uesPushMessage:userInfo];   
    7.     }  
    8.     RETURN YES;  
    9. }  

5: Clear the Notification center of the existing push message, only need to set the specified app Badge to 0

[CSharp]View Plaincopy
    1. [[UIApplication sharedapplication] setapplicationiconbadgenumber:0];


6: The active push string must conform to the following JSON array format in order to correctly push to the phone.

@"{

//Custom Parameters

\ "Userinfo\":

{

\ "name\": \ "Remote Notice\"

},

//Standard notation

\ "Aps\":

{

\ "Alert\":

{

\ "action-loc-key\": \ "open\",//multi-lingual support

\ "body\": \ "Messgae content\"//Message body

},

\ "Badge\": 1,//For the app's icon tag specific values

\ "sound\": \ "default\" //playback of audio files, default means the system defaults to select the column ringtone

}

}";

It's almost over by here.

IOS Remote Push 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.