Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix badge incrementing when cancelling display in foreground #998

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

#import "OSNotification+Internal.h"

#import "OneSignal.h"

#import "OneSignalCommonDefines.h"

#import "OneSignalUserDefaults.h"

@implementation OSNotification

OSNotificationDisplayResponse _completion;
Expand Down Expand Up @@ -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;
Expand Down