From 24e7af010b0635b7d5d14c6c1cb9bff61b91a4ee Mon Sep 17 00:00:00 2001 From: emawby Date: Wed, 22 Sep 2021 14:34:06 -0700 Subject: [PATCH] Reset the cached badge count if a notification is not displayed in foreground --- iOS_SDK/OneSignalSDK/Source/OSNotification.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/iOS_SDK/OneSignalSDK/Source/OSNotification.m b/iOS_SDK/OneSignalSDK/Source/OSNotification.m index 931432690..ca0aac1bb 100644 --- a/iOS_SDK/OneSignalSDK/Source/OSNotification.m +++ b/iOS_SDK/OneSignalSDK/Source/OSNotification.m @@ -27,12 +27,16 @@ #import +#import + #import "OSNotification+Internal.h" #import "OneSignal.h" #import "OneSignalCommonDefines.h" +#import "OneSignalUserDefaults.h" + @implementation OSNotification OSNotificationDisplayResponse _completion; @@ -298,6 +302,14 @@ - (void)setCompletionBlock:(OSNotificationDisplayResponse)completion { - (OSNotificationDisplayResponse)getCompletionBlock { OSNotificationDisplayResponse block = ^(OSNotification *notification){ + /* + If notification is null here then display was cancelled and we need to + reset the badge count to the value prior to receipt of this notif + */ + if (!notification) { + NSInteger previousBadgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber; + [OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:previousBadgeCount]; + } [self complete:notification]; }; return block;