From b2ea8c100d06b0a1a75be838e4c3b22fc226e194 Mon Sep 17 00:00:00 2001 From: Ajay Subramanya <118314354+ajaysubra@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:56:59 -0500 Subject: [PATCH] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index e305c237..31bf4dd5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ - [Request Push Notification Permission](#request-push-notification-permission) - [Receiving Push Notifications](#receiving-push-notifications) - [Tracking Open Events](#tracking-open-events) + - [Updating the badge](#updating-the-badge) - [Deep Linking](#deep-linking) - [Option 1: URL Schemes](#option-1-URL-schemes) - [Option 2: Universal Links](#option-2-universal-links) @@ -312,6 +313,18 @@ extension AppDelegate: UNUserNotificationCenterDelegate { ``` Once your first push notifications are sent and opened, you should start to see _Opened Push_ metrics within your Klaviyo dashboard. +#### Updating the badge + +If badge permissions were requested when requesting push permission please use the following code to decrement the badge count when handling opened push. + +```swift +if #available(iOS 16.0, *) { + UNUserNotificationCenter.current().setBadgeCount(UIApplication.shared.applicationIconBadgeNumber - 1) +} else { + UIApplication.shared.applicationIconBadgeNumber -= 1 +} +``` + #### Deep Linking > ℹ️ Your app needs to use version 1.7.2 at a minimum in order for the below steps to work.