Skip to content

Commit

Permalink
Merge pull request #1335 from OneSignal/rebase_fix_badge_clearing
Browse files Browse the repository at this point in the history
Fix badge clearing when calling clearAll
  • Loading branch information
emawby authored Nov 8, 2023
2 parents c2d4acf + 3da18b0 commit 2570a4d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ NS_SWIFT_NAME(onClick(event:));

+ (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID;
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened;
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll;

+ (BOOL)receiveRemoteNotification:(UIApplication* _Nonnull)application UserInfo:(NSDictionary* _Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler;
+ (void)notificationReceived:(NSDictionary* _Nonnull)messageDict wasOpened:(BOOL)opened;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ + (void)presentAppSettings {

+ (void)clearAll {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
// TODO: Determine if we also need to call clearBadgeCount
[self clearBadgeCount:false];
// removing delivered notifications doesn't update the badge count
[self clearBadgeCount:false fromClearAll:true];
}

+ (BOOL)registerForAPNsToken {
Expand Down Expand Up @@ -686,7 +686,7 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict
[self launchWebURL:notification.launchURL]; //TODO: where should this live?
}

[self clearBadgeCount:true];
[self clearBadgeCount:true fromClearAll:false];

NSString* actionID = NULL;
if (actionType == OSNotificationActionTypeActionTaken) {
Expand Down Expand Up @@ -755,7 +755,7 @@ + (void)displayWebView:(NSURL*)url {
openUrlBlock(true);
}

+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened {
+ (BOOL)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll {

NSNumber *disableBadgeNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:ONESIGNAL_DISABLE_BADGE_CLEARING];

Expand All @@ -764,8 +764,11 @@ + (BOOL)clearBadgeCount:(BOOL)fromNotifOpened {
else
_disableBadgeClearing = NO;

if (_disableBadgeClearing)
if (_disableBadgeClearing && !fromClearAll) {
// The customer could have manually changed the badge value. We must ensure our cached value will match the current state.
[OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:[UIApplication sharedApplication].applicationIconBadgeNumber];
return false;
}

bool wasBadgeSet = [UIApplication sharedApplication].applicationIconBadgeNumber > 0;

Expand Down
3 changes: 1 addition & 2 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ + (void)init {
}];
*/

[OSNotificationsManager clearBadgeCount:false];
[OSNotificationsManager clearBadgeCount:false fromClearAll:false];
[self startOutcomes];
[self startLocation];
[self startTrackIAP];
Expand Down Expand Up @@ -798,7 +798,6 @@ + (void)load {
*/
- (void)onesignalSetApplicationIconBadgeNumber:(NSInteger)badge {
[OneSignalExtensionBadgeHandler updateCachedBadgeValue:badge];

[self onesignalSetApplicationIconBadgeNumber:badge];
}

Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ + (void)applicationForegrounded {
// [OneSignal receivedInAppMessageJson:nil];
}

[OSNotificationsManager clearBadgeCount:false];
[OSNotificationsManager clearBadgeCount:false fromClearAll:false];
}

+ (void)applicationBackgrounded {
Expand Down

0 comments on commit 2570a4d

Please sign in to comment.