删除“远程通知"从通知中心 [英] Remove "remote notifications" from notification center

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

问题描述

我有以下问题:我的应用程序从自己的服务器接收一些远程通知只是为了向用户显示一些实用信息.我没有使用图标徽章,因为我不需要它.如果应用程序用户触摸来自 iOS 通知中心的远程通知,我的应用程序可以毫无问题地捕获它,我从 application:didFinishLaunchingWithOptions: 接收选项,或者,如果应用程序打开,我用 捕获远程通知application:didReceiveRemoteNotification: 选择器.但是,现在我想从 iOS 通知中心删除这些通知,因为这只是一条消息,我一直在其他帖子中寻找答案,我已经在我的应用程序中尝试了这些解决方案它们不起作用"

I have the following issue: "My app receive some remote notifications from an own server just to show to the user some practical information. I am not using a icon badge, because I don't need it. If the application user touch the remote notification from the iOS Notification Center my application can catch it without any problem, I receive the options from application:didFinishLaunchingWithOptions: or, if the application is open I catch the remote notification with application:didReceiveRemoteNotification: selector. But, now I want to remove these notifications from iOS Notification Center because It is just a message and I have been looking for the answer in another posts and I've tried these solutions in my app and they don't work"

接下来是一些解决方案:

Some solutions were the next:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {  
    [application cancelAllLocalNotifications];  
    application.applicationIconBadgeNumber = 0;  
    ...  
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    ...  
    if (launchOptions) {  
        [application cancelAllLocalNotifications];  
        application.applicationIconBadgeNumber = 0;  
    }  
    ...  
}

并且远程通知仍在 iOS 通知中心,我如何在没有任何棘手代码的情况下从该位置删除或者是 iOS SDK 问题?我认为不可能出现问题,因为 Tweetbot 应用在您进入该应用后会从 iOS 通知中心删除其远程通知.

And the remote notification still in the iOS Notification Center, how can I remove from that place without any tricky code or is an iOS SDK issue? I don't think that an issue was possible because Tweetbot app remove its remote notifications from iOS Notification Center after you enter to the app.

问候!

推荐答案

随着 iOS 10 及更高版本UNUserNotificationCenter 的引入,现在可以删除您应用的少数或全部远程通知.

With introduction of UNUserNotificationCenter for iOS 10 and above, it is now possible to remove few or all remote notifications of your app.

UNUserNotificationCenter 文档

使用此类的共享单例实例,可以管理设备上传递的远程通知.具体可以使用以下方法: func removeDeliveredNotifications(withIdentifiers: [String]) 如果您想删除应用的特定通知,或者 func removeAllDeliveredNotifications() 删除应用的所有通知.

With a shared singleton instance of this class, it is possible to manage delivered remote notifications on the device. Specifically, the following methods can be used: func removeDeliveredNotifications(withIdentifiers: [String]) if you want to remove specific notification of your app, OR func removeAllDeliveredNotifications() to remove all notifications of your app.

这篇关于删除“远程通知"从通知中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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