以编程方式从通知托盘中删除UILocalNotification [英] Removing UILocalNotification from notification tray programatically

查看:89
本文介绍了以编程方式从通知托盘中删除UILocalNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式从通知托盘中删除/解除 UILocalNotification
我可以取消删除通知的通知

Is there a way to programmatically remove/dismiss UILocalNotification from Notification Tray. I am able to cancel the notification which removes the notifications from

[[UIApplication sharedApplication] scheduledLocalNotifications]

这是我需要做的事情

我需要在执行操作后(即在用户点击通知后)从NotificationTray中解除 UILocalNotification

I need to dismiss the UILocalNotification from NotificationTray after the action has been performed(ie after the user taps the notification)

编辑:
我可以从 NSNotificationCenter 中删除​​通知。我想从通知托盘中删除特定通知。就像用户按下清除按钮清除属于特定应用程序的所有通知一样。

I can remove the notifications from the NSNotificationCenter. I want to remove specific notifications from the Notification Tray .Like the user presses the clear button to clear all the notifications belonging to a particular application.

推荐答案

您可以使用以下方式取消所有通知:

You can cancel all notifications using:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

如果要删除特定通知,可以使用 userinfo 的通知对象,当您创建本地通知时,为其添加唯一ID。稍后您可以使用该ID删除本地通知。

If you want to remove a particular notification, you can use userinfo of notification object, when you create a local notification add a unique ID to that. Later you can use that ID for removing local notification.

为此,您可以使用以下代码:

For that you can use the following code:

NSString *notificationId = @"id_to_cancel";
UILocalNotification *notification = nil;
for(UILocalNotification *notify in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
  if([[notify.userInfo objectForKey:@"ID"] isEqualToString:notificationId])
  {
     notification = notify;
     break;
  }
}
[[UIApplication sharedApplication] cancelLocalNotification:notification];

这篇关于以编程方式从通知托盘中删除UILocalNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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