Created
December 15, 2021 09:07
-
-
Save hanfengs/92807eb761a0501b24d45071f48b1cd5 to your computer and use it in GitHub Desktop.
[清理角标和通知]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iOS App如何清除badge并保留通知中心的消息 | |
//https://medium.com/@jasonyuh/ios-app%E5%A6%82%E4%BD%95%E6%B8%85%E9%99%A4badge%E5%B9%B6%E4%BF%9D%E7%95%99%E9%80%9A%E7%9F%A5%E4%B8%AD%E5%BF%83%E7%9A%84%E6%B6%88%E6%81%AF-e4d9f35f9ef5 | |
//https://www.jianshu.com/p/59878fd8053c | |
func applicationDidBecomeActive(_ application: UIApplication) { | |
// MARK: 角标重置 | |
application.applicationIconBadgeNumber = -1 | |
// MARK: 移除所有远程通知 | |
// 即将收到的 | |
UNUserNotificationCenter.current().removeAllPendingNotificationRequests() | |
// 已经收到的 | |
UNUserNotificationCenter.current().removeAllDeliveredNotifications() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment