Skip to content

Commit 0f1ae55

Browse files
committed
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.
1 parent 6d9b74c commit 0f1ae55

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -794,25 +794,22 @@ + (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll {
794794
_disableBadgeClearing = NO;
795795

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

802-
bool wasBadgeSet = [UIApplication sharedApplication].applicationIconBadgeNumber > 0;
803-
804-
if (fromNotifOpened || wasBadgeSet) {
805-
if (@available(iOS 16.0, *)) {
806-
[[UNUserNotificationCenter currentNotificationCenter] setBadgeCount:0 withCompletionHandler:^(NSError * _Nullable error) {
807-
if (error) {
808-
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"clearBadgeCount encountered error setting badge count: %@", error]];
809-
}
810-
}];
811-
} else {
812-
[OneSignalCoreHelper runOnMainThread:^{
813-
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
814-
}];
815-
}
803+
if (@available(iOS 16.0, *)) {
804+
[[UNUserNotificationCenter currentNotificationCenter] setBadgeCount:0 withCompletionHandler:^(NSError * _Nullable error) {
805+
if (error) {
806+
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"clearBadgeCount encountered error setting badge count: %@", error]];
807+
}
808+
}];
809+
} else {
810+
[OneSignalCoreHelper runOnMainThread:^{
811+
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
812+
}];
816813
}
817814
}
818815

0 commit comments

Comments
 (0)