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