ios 从通知中心删除单个远程通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9925854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:37:12  来源:igfitidea点击:

Remove single remote notification from Notification Center

iosipadpush-notification

提问by MaTTP

my app receives remote notification from Apple server.

我的应用程序从 Apple 服务器接收远程通知。

Is there a way to remove a single remote notification from notification center (the drop-down menu available from iOs 5.0+), when the user taps on it?

当用户点击它时,有没有办法从通知中心(iOs 5.0+ 提供的下拉菜单)中删除单个远程通知?

enter image description here

在此处输入图片说明

Thanks!

谢谢!

回答by Javier Soto

There is no way to remove a specific notification as of iOS SDK 5.0. The way to remove all the notificationsfrom your app so they don't show in the Notification Center when the user opens the app from one of them, is to set the app badge to 0, like this:

从 iOS SDK 5.0 开始,无法删除特定通知。从您的应用程序中删除所有通知以便当用户从其中之一打开应用程序时它们不会显示在通知中心中的方法是将应用程序徽章设置为 0,如下所示:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

EDIT: on iOS 8, SpringBoard seems to be automatically dismissing a notification when you tap on it on the Notification Center to open the app.

编辑:在 iOS 8 上,当您在通知中心点击它以打开应用程序时,SpringBoard 似乎会自动关闭通知。

回答by Vamos

Here is a suggestion, though it does have its flaws, and I haven't tried it myself:

这是一个建议,虽然它确实有缺陷,但我自己还没有尝试过:

  • Push a silent notification (contentAvailable:true), don't include a "alert" inside the push, place the alert text in a custom property of the push
  • Handle the incoming push and trigger a local notification, display it immediately
  • If the user clicks the local notification, use the [UIApplication cancelLocalNotification:] which should remove the notification from the notification center.
  • 推送无声通知(contentAvailable:true),推送中不要包含“alert”,将alert文本放在推送的自定义属性中
  • 处理传入的推送并触发本地通知,立即显示
  • 如果用户单击本地通知,请使用 [UIApplication cancelLocalNotification:] 从通知中心删除通知。

回答by MyXEDNotes

When you call the method: [application cancelAllLocalNotifications];inside the AppDelegate methods:

当您调用该方法时: [application cancelAllLocalNotifications];在 AppDelegate 方法中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

and

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

All Local and Push Notifications will be remove on that for the particular app.

将删除特定应用程序的所有本地和推送通知。