下次启动应用程序时,可以取消本地通知吗? [英] Can I dismiss the local notification when next time the app launch?

查看:90
本文介绍了下次启动应用程序时,可以取消本地通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当用户在通知中心点击此通知时,我可以取消该通知.但是我可以在无法从系统获取相关本地通知的其他地方取消该通知.我可以序列化本地通知,并在下次运行该应用程序时取消它吗?

I know I can cancel the notification when user tap this notification in notification center . But can I cancel the notification in other palce where I can't get the related local notification from system. Can I serialize the local notification, and cancel it when the app runs next time?

很抱歉让您误会了!

我想在通知中心关闭已发布的通知,而不是预定的. 因此,我想问的是如何保存本地通知对象,然后在下次启动应用程序时将其关闭.也许当前的sdk无法完成此工作.

I want to dismiss a posted notification in the notification center, but not a scheduled one. So what I want to ask is how to save the local notification object, then I can use it dismiss itself when next time the app launch. Maybe this job can't be done with current sdk.

推荐答案

如果您需要取消所有通知,则可以使用:

If you need to cancel all notification you can use:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

要取消特定通知:

[[UIApplication sharedApplication] cancelLocalNotification:aNotification];

要获取特定的通知,您可以使用:

For getting the particular Notification you can use:

NSArray *notifArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (int i = 0; i < [notifArray count]; i++)
{
    UILocalNotification *aEvent = [notifArray objectAtIndex:i];
    NSDictionary *userInfo = aEvent.userInfo;
    NSString *notifId=[NSString stringWithFormat:@"%@",[userInfo valueForKey:@"id"]];
    if ([id isEqualToString:cancelId])
    {
        [[UIApplication sharedApplication] cancelLocalNotification:aEvent];
        break;
    }
}

这里:

  • 您需要在通知的userInfo中存储一个ID键值对,以标识特定的本地通知
  • cancelId是要取消的通知的ID(存储在用户信息中)
  • You need to store a id key value pair in the userInfo of your notification for identifying particular local notification
  • cancelId is the id of notification which you want to cancel (Stored in user info)

这篇关于下次启动应用程序时,可以取消本地通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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