如何识别ios sdk中的特定通知 [英] how to identify a particular notification in ios sdk

查看:109
本文介绍了如何识别ios sdk中的特定通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

示例:

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

现在我有情况删除第二个通知我该怎么办...
请帮帮我..
提前感谢..

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

推荐答案

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

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.

就像你可以这样做


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

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

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

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

这篇关于如何识别ios sdk中的特定通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆