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

发布于 2024-12-08 19:29:04 字数 1474 浏览 0 评论 0原文

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

示例:

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

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

actually am developing an alarm project,
now i have a doubt on Local notification. how can i identify a particular notification.
we can't even set tag to local notification then how can i differentiate them.

example:

notification: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];

notification: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];

now i'm in situation to delete the second notification how can i do it...
please help me..
thanks in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2024-12-15 19:29:04

我的猜测是,使用 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];


        }

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

My guess is that use the userInfo for distinguishing the local notifications that would be a better idea but for that you need to set the userInfo of the local notification.

Like you could do something like this

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

            NSLog(@"This is notification 1");
        }

now for your second requirement i.e for the deleting part do you want to delete the notification when it is identified as n1 or n2 then in that case you could modify the above code and add this

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

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


        }

Place the above code as per your convenience

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文