【发布时间】:2022-01-21 13:33:33
【问题描述】:
我使用本地通知向用户传递消息的同时我想在通知触发时更新应用程序徽章,但是本地通知委托具有处理应用程序在前台和当应用程序处于前台时的通知的功能用户与通知交互(比如点击它)。当通知触发并且应用处于后台时,有什么方法可以更新应用徽章?
当应用在前台时处理通知
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// run code when app in foreground
}
在点击操作时处理通知
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// run code when user interact with notification only
}
【问题讨论】:
-
您不会仅仅因为触发了本地通知而收到事件。
标签: ios swift unusernotificationcenter