简体   繁体   English

如何使用本地通知更新应用程序徽章

[英]How to Update App Badge with Local Notification

I used local notification to deliver a message to the user at the same time I want to update App badge when the notification triggers, but the local notification delegate have functions that deal with notifications when the app is in the foreground and when the user interacts with notification (like a tap on it).我使用本地通知向用户传递消息的同时我想在通知触发时更新应用程序徽章,但是本地通知委托具有在应用程序处于前台以及用户交互时处理通知的功能通知(就像点击它)。 Is there any way to update the app badge when the notification triggers and the app is in background?当通知触发并且应用程序处于后台时,有什么方法可以更新应用程序徽章?

Handle notification when the app is in the foreground当应用程序在前台时处理通知

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    // run code when app in foreground
    
}

Handle notification when the tap action on it在点击操作时处理通知

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    // run code when user interact with notification only
}

To update App badge when local notification trigger set the badge value in the code bellow when set the notification:要在本地通知触发时更新应用程序徽章,请在设置通知时在下面的代码中设置徽章值:

func schedulNotification() {
let content = UNMutableNotificationContent()
content.badge = 1  // That will appear on app icon when notification trigger
// Continue notification settings...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift-交付应用程序上的本地通知图标徽章编号更新处于后台 - Swift - Local notification icon badge number update on deliver App is in background 如何更新通知徽章编号? - How to update notification badge number? 在应用程序处于后台时使用推送通知更新徽章 - Update badge with push notification while app in background 如何更新IOS推送通知中的徽章编号? - How to update the badge number in IOS push notification? 如何在接收通知时更新tabBar徽章值 - How to update tabBar badge value on receiving notification 本地通知中的“应用程序图标”标志是否会从“推送通知”有效载荷标志中被覆盖? - Does a App Icon badge from a local notification get overridden from a Push Notification payload badge? Phonegap 3.0及更高版本-是否有无需更新通知即可更新应用程序徽章的插件? - Phonegap 3.0 and newer - Is there a Plugin to Update the App Badge without a Push Notification? 在App未打开时收到推送通知时更新徽章编号 - Update Badge Number when push notification is received when App is not Open 本地推送通知徽章编号 - local push notification badge number 更新推送通知徽章计数 - Update push notification badge count
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM