Recently in an e-commerce app, saying this year e-commerce is very hot ah. A local notice was used to tidy up the
Add a local notification to the system with the following code:
Initialize local notification object uilocalnotification *notification = [[Uilocalnotification alloc] INIT];IF (notification) {//Set reminder time for notifications NSDate *currentdate = [NSDate Date]; Notification.timezone = [Nstimezone defaulttimezone]; Use local time zone notification.firedate = [currentdate datebyaddingtimeinterval:5.0]; Set repeat interval notification.repeatinterval = kcfcalendarunitday; Set the text content of the reminder notification.alertbody = @ "Wake up, man"; Notification.alertaction = nslocalizedstring (@ "Take medicine", nil); Notification tones use the default notification.soundname= uilocalnotificationdefaultsoundname; Set the number of reminders in the top right corner of the application notification.applicationiconbadgenumber++; Sets the userinfo of the notification to identify the notification nsmutabledictionary *auserinfo = [[Nsmutabledictionary alloc] init]; Auserinfo[klocalnotificationid] = @ "Localnotificationid"; Notification.userinfo = Auserinfo; Add notifications to the system [[UIApplication sharedapplication] schedulelocalnotification:notification];}
Add code to accept local notifications in APPDELEGATE.M:
After receiving the notification, the following methods in the calling program delegate are processed://Of course the method can be jump to the specified page, and so on, here is a popup box
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{ NSLog (@ "Application did receive local notifications"); Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Hello" message:@ "Welcome" Delegate:nil cancelbuttontitle:@ " OK "otherbuttontitles:nil, nil"; [Alert show];
}
Recently read Daniel's blog, said to be local notice in the app uninstall, there will also exist in the system,
You can look at it, print it all, check it out.
12NSArray *localnotifications = [[UIApplication sharedapplication] scheduledlocalnotifications]; NSLog (@ "%@", localnotifications);
So how to delete local notifications, Daniel also gives a method
The cancellation method is divided into two types.
The first is to compare violence and cancel all local notifications directly:
[[UIApplication sharedapplication] cancelalllocalnotifications];
The second method is for a specific notification:
-(void) Cancellocalnotification: (uilocalnotification *) notification ns_available_ios (4_0);
It is then necessary to notify that there is an identity so that we can locate which notification is. can be specified in notification's userinfo (a dictionary).
For example:
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{ NSLog (@ "Application did receive local notifications"); Cancels a specific local notification for (uilocalnotification *noti in [[UIApplication sharedapplication] scheduledlocalnotifications]) { NSString *notiid = Noti.userinfo[klocalnotificationid]; NSString *receivenotiid = Notification.userinfo[klocalnotificationid]; if ([Notiid isequaltostring:receivenotiid]) { [[uiapplication sharedapplication] Cancellocalnotification: Notification]; return; } } Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Hello" message:@ "Welcome" Delegate:nil cancelbuttontitle:@ " OK "otherbuttontitles:nil, nil"; [Alert show];}
iOS Local notifications: uilocalnotification