如何识别ios sdk中的特定通知

实际上正在开发一个报警项目,现在我对本地通知有疑问。 我怎样才能确定一个特定的通知。 我们甚至不能将标签设置为本地通知,那么我怎样才能区分它们。

例:

通知:1

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = selectedDate; localNotification.alertBody = @"you got work"; localNotification.alertAction = @"Snooze"; localNotification.repeatInterval = NSDayCalendarUnit; localNotification.soundName = UILocalNotificationDefaultSoundName; NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil]; localNotification.userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [localNotification release]; 

通知:2,

 UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = another selectedDate; localNotification.alertBody = @"i got work"; localNotification.alertAction = @"Snooze"; localNotification.repeatInterval = NSDayCalendarUnit; localNotification.soundName = UILocalNotificationDefaultSoundName; NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil]; localNotification.userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [localNotification release]; 

现在我在情况下删除第二次通知我该怎么做…请帮助我..在此先感谢..

我的猜测是使用userInfo来区分本地通知,这将是一个更好的主意,但为此,您需要设置本地通知的userInfo。

就像你可以做这样的事情

  if([Your_notification_Object.userInfo valueForKey:@“Key 1”] == @“Object 1”){

             NSLog(@“This is notification 1”);
         }

现在为您的第二个要求即删除部分是否要删除通知时,它被确定为n1或n2那么在这种情况下,你可以修改上面的代码,并添加

 if([Your_notification_Object.userInfo valueForKey:@“Key 1”] == @“Object 1”){

             NSLog(@“This is notification 1”);
 [[UIApplication sharedApplication] cancelLocalNotification:Your_notification_Object];


         }

根据您的方便,放置上面的代码