IOS Local Push Uilocalnotification

Source: Internet
Author: User

Create a notification

Uilocalnotification *notification = [[Uilocalnotification alloc] init];        if (notification) {NSDate *now = [NSDate new]; Notification.firedate = [now datebyaddingtimeinterval:10]; Notify Notification.repeatinterval=0 after 10 seconds; Repetition times, Kcfcalendarunitweekday once a week notification.timezone = [Nstimezone defaulttimezone]; Set time zone Notification.applicationiconbadgenumber = 1; Application of the angular mark notification.soundname = Uilocalnotificationdefaultsoundname; Sound, can be replaced alarm.soundname = @ "sound.wav"//Remove the following 2 lines will not pop up the prompt box Notification.alertbody = @ "Notification content"; Prompt message popup box notification.alertaction = @ "OPEN"; Cue box button//notification.hasaction = NO;        Whether to show extra buttons for no when alertaction disappears nsdictionary *infodict = [nsdictionary dictionarywithobject:@ "value" forkey:@ "key"];                Setting the UserInfo is convenient to use when you need to undo later, you can also pass other values, when the notification trigger can get notification.userinfo = infodict;    [[UIApplication sharedapplication] schedulelocalnotification:notification]; }


What to push
Content pushed-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification*) notification{    //Here, you can do something you want to do by notification Useinfo,    if ([[Notification.userinfo objectforkey:@ "Key" ] {isequaltostring:@ "value"])    {           Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "system hint" message:@ " There is a serious threat to your system "Delegate:nil cancelbuttontitle:@" close "Otherbuttontitles:nil,nil";           [Alert show];            }    Application.applicationiconbadgenumber = 0; Remove Corner Mark}

-(void) Applicationdidbecomeactive: (uiapplication *) application{    //Do not push through the app icon to open the app remove corner label    Application.applicationiconbadgenumber = 0;}

Cancel Notification
Get all current local notifications    Nsarray *notificaitons = [[UIApplication sharedapplication] scheduledlocalnotifications];    if (!notificaitons | | notificaitons.count <= 0)    {        return;    }    Cancels a specific notification for    (uilocalnotification *notify in notificaitons)    {        if ([[Notify.userinfo objectforkey:@] Key "] isequaltostring:@" value "]        {            [[uiapplication sharedapplication] cancellocalnotification:notify];            break;        }    }    //Cancel all local notifications//    [[UIApplication sharedapplication] cancelalllocalnotifications];



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS Local Push Uilocalnotification

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.