Code in the APPDELEGATE.M
APPDELEGATE.M-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (NSDictionary *) launchoptions { //handling IOS8 Local push cannot receive the problem float sysversion=[[uidevice currentdevice]systemversion].floatvalue; if (sysversion>=8.0) { Uiusernotificationtype Type=uiusernotificationtypebadge | Uiusernotificationtypealert | Uiusernotificationtypesound; Uiusernotificationsettings *setting=[uiusernotificationsettings Settingsfortypes:type Categories:nil]; [[UIApplication sharedapplication]registerusernotificationsettings:setting]; } return YES;}
Receive local push (added in APPDELEGATE.M)-(void) Application: (UIApplication *) application didreceivelocalnotification: ( Uilocalnotification *) notification{ Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "title" Message: Notification.alertbody delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil]; [Alert show]; The number on the icon is reduced by 1 application.applicationiconbadgenumber-= 1;}
-(void) Applicationwillenterforeground: (uiapplication *) application { //when opening the app directly, the number on the icon is clear 0 Application.applicationiconbadgenumber = 0;}
Code that is added in the calling class
Push method//Set local push parameters and push-(void) schedulenotification{uilocalnotification *notification = [[Uilocalnotification All OC] init]; Set 5 seconds after nsdate *pushdate = [NSDate datewithtimeintervalsincenow:5]; if (notification! = nil) {//Set push time (after 5 seconds) notification.firedate = pushdate; Set the time zone (this is the default time zone) Notification.timezone = [Nstimezone defaulttimezone]; Set repeat interval (default 0, no repeat push) Notification.repeatinterval = 0; Push sound (system default) Notification.soundname = Uilocalnotificationdefaultsoundname; Push content Notification.alertbody = @ "Push main content"; The number shown on the icon Notification.applicationiconbadgenumber = 1; Setting the UserInfo is convenient to use nsdictionary *info = [nsdictionary dictionarywithobject:@ "name" forkey:@ "key" when you need to revoke it later]; Notification.userinfo = info; Add push to uiapplication uiapplication *app = [UIApplication sharedapplication]; [App Schedulelocalnotification:notification]; }}
iOS local push implementation, compatible with IOS8