在網上搜索了很多之後,我得到了,我們不能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;
}
}
}
希望大家能夠從中得到好處的功能。祝你好運
可能的重複http://stackoverflow.com/questions/3842252/is-there-a-simple-way-to-edit-modify-a-uilocalnotification – John
是的!但不幸的是我不能接觸到這個問題。並且它對我也沒什麼幫助。 – iOmi