Skip to content

Commit 24e7af0

Browse files
committed
Reset the cached badge count if a notification is not displayed in foreground
1 parent 6f71c9d commit 24e7af0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

iOS_SDK/OneSignalSDK/Source/OSNotification.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727

2828
#import <Foundation/Foundation.h>
2929

30+
#import <UIKit/UIKit.h>
31+
3032
#import "OSNotification+Internal.h"
3133

3234
#import "OneSignal.h"
3335

3436
#import "OneSignalCommonDefines.h"
3537

38+
#import "OneSignalUserDefaults.h"
39+
3640
@implementation OSNotification
3741

3842
OSNotificationDisplayResponse _completion;
@@ -298,6 +302,14 @@ - (void)setCompletionBlock:(OSNotificationDisplayResponse)completion {
298302

299303
- (OSNotificationDisplayResponse)getCompletionBlock {
300304
OSNotificationDisplayResponse block = ^(OSNotification *notification){
305+
/*
306+
If notification is null here then display was cancelled and we need to
307+
reset the badge count to the value prior to receipt of this notif
308+
*/
309+
if (!notification) {
310+
NSInteger previousBadgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
311+
[OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:previousBadgeCount];
312+
}
301313
[self complete:notification];
302314
};
303315
return block;

0 commit comments

Comments
 (0)