在这之前,当然还要在didFinishLaunchingWithOptions注册通知。
//下面是发送通知
NSArray *arr = [UIApplication sharedApplication].scheduledLocalNotifications;
for (UILocalNotification *notify in arr) {
// 通过category判断,或者可以通过notify.userInfo来判断
if ([notify.category isEqualToString:@"34234234"]) {
[[UIApplication sharedApplication] cancelLocalNotification:notify];
NSLog(@"isremove");
}
}
UILocalNotification *localNoti = [[UILocalNotification alloc] init];
localNoti.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNoti.alertTitle = @"标题";
localNoti.alertBody = @"哈哈,本地推送";
localNoti.applicationIconBadgeNumber = 1;
localNoti.soundName = UILocalNotificationDefaultSoundName;
localNoti.category = @"34234234";
// 还可以携带信息,这样可以处理收到通知,做什么处理
localNoti.userInfo = @{@"selectIndex" : @(2)};
[[UIApplication sharedApplication] scheduleLocalNotification:localNoti];
// 立即发
[[UIApplication sharedApplication] presentLocalNotificationNow:localNoti];