iOS 本地通知 操作
1:配置通知:然后退出程序;
UILocalNotification *localNotif = [[UILocalNotification alloc] init]; localNotif.fireDate = date; // date after 10 sec from now localNotif.timeZone = [NSTimeZone defaultTimeZone]; // Notification details localNotif.alertBody = text; // text of you that you have fetched // Set the action button localNotif.alertAction = @"View"; localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; // Specify custom data for the notification NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; localNotif.userInfo = infoDict; // Schedule the notification [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
2:接收通知,打开操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the view controller‘s view to the window and display. [window addSubview:viewController.view]; [window makeKeyAndVisible]; application.applicationIconBadgeNumber = 0; // Handle launching from a notification UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotif) { NSLog(@"Recieved Notification %@",localNotif); } return YES; } - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { // Handle the notificaton when the app is running NSLog(@"Recieved Notification %@",notif); }