Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove all usages of deprecated applicationIconBadgeNumber
* applicationIconBadgeNumber is deprecated and reports of apps hanging have been submitted, let's move off it.
* In clearBadgeCount, we read if badge was > 0 before setting badge to 0. Since we can't read accurately, let's just always set to 0, which is what the old logic effectively did anyways.
  • Loading branch information
nan-li committed May 28, 2025
commit 0f1ae550ebc08fe5e659b42a0f05abaa90336251
Original file line number Diff line number Diff line change
Expand Up @@ -794,25 +794,22 @@ + (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll {
_disableBadgeClearing = NO;

if (_disableBadgeClearing && !fromClearAll) {
// The customer could have manually changed the badge value. We must ensure our cached value will match the current state.
[OneSignalBadgeHelpers updateCachedBadgeValue:[UIApplication sharedApplication].applicationIconBadgeNumber];
// The developer could have manually changed the badge value but we cannot read the current state.
// We swizzle badge count setters, which should be sufficient to ensure the cached value matches the current state.
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"clearBadgeCount called but badge clearing is disabled, not updating cached badge count"];
return;
}

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

if (fromNotifOpened || wasBadgeSet) {
if (@available(iOS 16.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] setBadgeCount:0 withCompletionHandler:^(NSError * _Nullable error) {
if (error) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"clearBadgeCount encountered error setting badge count: %@", error]];
}
}];
} else {
[OneSignalCoreHelper runOnMainThread:^{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}];
}
if (@available(iOS 16.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] setBadgeCount:0 withCompletionHandler:^(NSError * _Nullable error) {
if (error) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"clearBadgeCount encountered error setting badge count: %@", error]];
}
}];
} else {
[OneSignalCoreHelper runOnMainThread:^{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}];
}
}

Expand Down