Ios--pushnotification Study and summary (push mechanism)

Source: Internet
Author: User

The first step is familiar with pushnotification and create a certificate, you can use the following website to familiarize yourself with the following

http://blog.csdn.net/daydreamingboy/article/details/7977098 (Implementation of the simple push notification (push Notification) on iOS)


Second step, find a demo to learn: I'm looking for a demo on GitHub

Https://github.com/Turkcell/PushNotification_iOS_sdk


In the code, do the following things:

 #pragma mark --------Remote Notification-(void) registerapnsnotification{//adaptation 8.0,if Walk 8.0 if (![ [Nsuserdefaults Standarduserdefaults] Boolforkey:koatosparamsdevicetoken]) {if ([[UIApplication SharedApplicati On] Respondstoselector: @selector (registerusernotificationsettings:)]) {Uiusernotificationsettings *settings = [Uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge| uiusernotificationtypesound|            Uiusernotificationtypealert Categories:nil];        [[UIApplication sharedapplication] registerusernotificationsettings:settings]; }else {[[uiapplication sharedapplication] registerforremotenotificationtypes:uiremotenotificationtypebadge | U Iremotenotificationtypealert |        Uiremotenotificationtypesound]; }            }}
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{[self registerapnsnotification];//Clear all local notifications    [application cancelalllocalnotifications];    Application.applicationiconbadgenumber = 0;}

-(void) Applicationwillterminate: (uiapplication *) application{    if ([[UIApplication sharedapplication] Enabledremotenotificationtypes] = = Uiremotenotificationtypenone &&!islogout) {         [self Registerapnsnotification];    }    Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}

Registered remote notification SUCCEEDED-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: ( NSData *) devicetoken{    nsstring *token = [NSString stringwithformat:@ "%@", [[[Devicetoken description] stringbyreplacingoccurrencesofstring:@ "<" withstring:@ ""] stringbyreplacingoccurrencesofstring:@ ">" withstring:@ ""];    DLog (@ "devicetoken[%@]", token);    [[Nsuserdefaults Standarduserdefaults] Setobject:token Forkey:koatosparamsdevicetoken];}

Registered remote notification failed-(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: ( Nserror *) error{    nsstring *error_str = [NSString stringWithFormat: @ "%@", error];    DLog (@ "Get Devicetoken failed [%@]", ERROR_STR);}


Ios--pushnotification Study and summary (push mechanism)

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.