【问题标题】:how to identify a particular notification in ios sdk如何在 ios sdk 中识别特定通知
【发布时间】:2011-10-07 13:32:55
【问题描述】:

其实是在开发一个报警项目, 现在我对本地通知有疑问。我如何识别特定通知。 我们甚至不能将标签设置为本地通知,那么我该如何区分它们。

示例:

通知: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];

现在我要删除第二个通知我该怎么做... 请帮我.. 提前谢谢..

【问题讨论】:

    标签: ios uilocalnotification


    【解决方案1】:

    我的猜测是,使用 userInfo 来区分本地通知会更好,但为此您需要设置本地通知的 userInfo。

    就像你可以做这样的事情

    if ([Your_notification_Object.userInfo valueForKey:@"Key 1"]==@"Object 1") { NSLog(@"这是通知 1"); }

    现在对于您的第二个要求,即删除部分,您是否要在通知被标识为 n1 或 n2 时删除通知,那么在这种情况下,您可以修改上述代码并添加此

    if ([Your_notification_Object.userInfo valueForKey:@"Key 1"]==@"Object 1") { NSLog(@"这是通知 1"); [[UIApplication sharedApplication] cancelLocalNotification:Your_notification_Object]; }

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

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多