about using local push processing uilocalnotification

Source: Internet
Author: User
uilocalnotification There are times when we need to deal with some local push and small details.
//judged that he was not active in the foreground before sending the push if ([UIApplication sharedapplication].applicationstate,!= uiapplicationstateactive) {//local push uilocalnotification *localnotification = [[Uilo
                    Calnotification alloc] init]; Localnotification.alertbody = @ "You just finished a trip, go and see the score."
                    "; Localnotification.alertaction = @ "You just finished a trip, go and see the score."
                    ";
                    Localnotification.applicationiconbadgenumber = 1;
                    Localnotification.soundname = Uilocalnotificationdefaultsoundname;
                    NSString * Tripid = [nsstring stringwithformat:@ '%ld ', (long) ((Trip *) extras). Starttimestamp];
                    Localnotification.userinfo = @{@ "Tripid": Tripid};
                    [[UIApplication sharedapplication] presentlocalnotificationnow:localnotification];
                NSLog (@ "T_trip_finished has sent push success%@-" userinfo%@ ", extras,localnotification.userinfo); }
Please do not forget to set the notification type and voice number prompts, as well as authorization. And do not forget when the click is not pushed to the null situation to exclude
Uiusernotificationsettings *setting = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge | Uiusernotificationtypesound | Uiusernotificationtypealert Categories:nil];
    Authorization Notice
    [[uiapplication sharedapplication] registerusernotificationsettings:setting];
      Notice jump, app by clicking on the top push to start app, get push, if not NULL, execute push method
    uilocalnotification* localnotification = [launchoptions Objectforkey:uiapplicationlaunchoptionslocalnotificationkey];
    if (localnotification) {//If the notification is not empty, click the Push startup app
        [self checkNotification:localNotification.userInfo islaunch:yes] ;
    }
    -(void) Checknotification: (nsdictionary *) userInfo islaunch: (BOOL) islaunch{
    //judge whether the data carried by the notification exists if
    (tripid && tripid.length > 0) {
        if (islaunch) {
            //Click Notification Launch app, jump to the interface corresponding to the notification

        }else{
            //Click Notice to reactivate the app, Jump to the corresponding interface

}
And of course we need to change the number of red dots. Display and hide don't forget.
-(void) Applicationdidenterbackground: (uiapplication *) application {
     [[uiapplication sharedapplication] SETAPPLICATIONICONBADGENUMBER:0];
}
-(void) Applicationwillenterforeground: (uiapplication *) application {
    //Set the number in the upper-right corner of the application picture (if you want to cancel the number in the upper right corner, Direct the value of this parameter to 0
    [[uiapplication sharedapplication] setapplicationiconbadgenumber:0];
}

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.