gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 10:37:35 25 4
gpt4 key购买 nike

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

例子:

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

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

关于ios - 如何识别 ios sdk 中的特定通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7688008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com