IOS local push implementation, compatible with iOS 8
Code in AppDelegate. m
// AppDelegate. m medium-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// process the problem that iOS8 cannot receive locally. float sysVersion = [[UIDevice currentDevice] systemVersion]. floatValue; if (sysVersion> = 8.0) {UIUserNotificationType = metric | uiusernotiftypetypesound; UIUserNotificationSettings * setting = [UIUserNotificationSettings Syntax: type categories: nil]; [UIApplication sharedApplication] usage: setting];} return YES ;}
// Receive local push (AppDelegate. add in 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 minus 1 application. applicationIconBadgeNumber-= 1 ;}
-(Void) applicationWillEnterForeground :( UIApplication *) application {// when the app is directly opened, the number on the icon is reset to application. applicationIconBadgeNumber = 0 ;}
Code added to the called class
// Push method // set local push parameters and push-(void) scheduleNotification {UILocalNotification * notification = [[UILocalNotification alloc] init]; // set NSDate * pushDate = [NSDate dateWithTimeIntervalSinceNow: 5]; if (notification! = Nil) {// set the push time (5 seconds later) notification. fireDate = pushDate; // set the time zone (this is the default time zone) notification. timeZone = [NSTimeZone defaultTimeZone]; // sets the repetition interval (0 by default, no repeated push) notification. repeatInterval = 0; // push sound (default) notification. soundName = UILocalNotificationDefaultSoundName; // push content notification. alertBody = @ "push subject content"; // digital notification displayed on the icon. applicationIconBadgeNumber = 1; // set userinfo to enable NSDictionary * info = [NSDictionary dictionaryWithObject: @ "name" forKey: @ "key"]; notification. userInfo = info; // Add push to UIApplication * app = [UIApplication sharedApplication]; [app scheduleLocalNotification: notification];}