在互联网上搜索了很多之后,我得到了一个我们无法edit
添加 UILocal 通知的东西。但可以肯定的是,我发现了另一种方法。
- 获取您设备的所有本地通知。
- 搜索相应的本地通知
- 取消该通知
- 创建一个新的
下面是添加通知的方法。
-(void)setLocalNotification
{
UILocalNotification *eventLocalNotification = [[UILocalNotification alloc]init];
eventLocalNotification.fireDate = //set firing Date of NSDate type
eventLocalNotification.timeZone = [NSTimeZone defaultTimeZone];
eventLocalNotification.alertBody = [NSString stringWithFormat:@"An event has arrived\n Event Name: %@",notificationName.Text];
eventLocalNotification.soundName = UILocalNotificationDefaultSoundName;
if ([repeat isEqualToString:@"Once"]){
eventLocalNotification.repeatInterval = 0;
}else if ([repeat isEqualToString:@"Daily"]){
eventLocalNotification.repeatInterval = NSDayCalendarUnit;
}else if ([repeat isEqualToString:@"Weekly"]){
eventLocalNotification.repeatInterval = NSWeekCalendarUnit;
}else if ([repeat isEqualToString:@"Monthly"]){
eventLocalNotification.repeatInterval = NSMonthCalendarUnit;
}else if ([repeat isEqualToString:@"Yearly"]){
eventLocalNotification.repeatInterval = NSYearCalendarUnit;
}
NSDictionary *info = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@",notificationName.text] forKey:@"name"];
eventLocalNotification.userInfo = info;
NSLog(@"notification userInfo gets name : %@",[info objectForKey:@"name"]);
[[UIApplication sharedApplication] scheduleLocalNotification:eventLocalNotification];
NSLog(@"Notification created");
}
下面是取消通知的功能
-(void)cancelLocalNotification
{
UILocalNotification * notificationToCancel=nil;
for(UILocalNotification * aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
NSLog(@"%@",[aNotif.userInfo objectForKey:@"name"]);
if([[aNotif.userInfo objectForKey:@"name"] isEqualToString:notificationName ])
{
notificationToCancel = aNotif;
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
NSLog(@"Notification Cancelled");
break;
}
}
}
希望您能从中受益。祝你好运