I am trying to update the badge count when a push notification is delivered via the Notification Service Extension. This is all working except that when reading UserDefaults from a shared AppGroup, the app is soft-opened and that causes an issue as I have biometric authentication running upon app launch. If biometric auth fails the user is presented with a username/password login screen. That is the screen that is being displayed if I update the badge count via UserDefaults.
Here's my Notification Service Extension code for the badge count:
if let userDefaults = UserDefaults(suiteName: "group.com.myApp.app") {
let badgeCount = userDefaults.integer(forKey: "badgeCount")
if badgeCount > 0 {
userDefaults.set(badgeCount + 1, forKey: "badgeCount")
bestAttemptContent.badge = badgeCount + 1 as NSNumber
} else {
userDefaults.set(1, forKey: "badgeCount")
bestAttemptContent.badge = 1
}
}
I need a way to get the current badge count and update it via the Notification Service Extension because the badge count is reduced as the user completes tasks within the app. So, I'm not trying to clear it upon app launch. I just need the badge count to be updated without the app launching and thus bypassing the biometric authentication.