[英]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.