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

查看:69
本文介绍了以编程方式从通知托盘中删除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天全站免登陆