Skip to content

Commit adee5bb

Browse files
authored
Remove a few applicationIconBadgeNumber API calls (#24877)
1 parent 3bf316d commit adee5bb

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

Tests/KeystoneTests/Tests/Features/Notifications/NotificationsViewControllerTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import XCTest
22
import WordPressData
3+
import UserNotifications
34
@testable import WordPress
45

56
final class NotificationsViewControllerTests: XCTestCase {
@@ -46,7 +47,7 @@ final class NotificationsViewControllerTests: XCTestCase {
4647
func testResetApplicationBadgeWhenAccountChange() throws {
4748
// Give
4849
let newUnreadCount = 1
49-
UIApplication.shared.applicationIconBadgeNumber = 0
50+
UNUserNotificationCenter.current().setBadgeCount(0)
5051
ZendeskUtils.unreadNotificationsCount = newUnreadCount
5152

5253
// When

WordPress/Classes/Utility/Notifications/PushNotificationsManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final class PushNotificationsManager: NSObject {
7575
sharedApplication.registerForRemoteNotifications()
7676
}
7777
sharedApplication.unregisterForRemoteNotifications()
78-
sharedApplication.applicationIconBadgeNumber = 0
78+
UNUserNotificationCenter.current().setBadgeCount(0)
7979
didRegisterForRemoteNotifications = false
8080
}
8181

@@ -187,7 +187,7 @@ public final class PushNotificationsManager: NSObject {
187187

188188
// Badge: Update
189189
if let badgeCountNumber = userInfo.number(forKeyPath: Notification.badgePath)?.intValue {
190-
sharedApplication.applicationIconBadgeNumber = badgeCountNumber
190+
UNUserNotificationCenter.current().setBadgeCount(badgeCountNumber)
191191
}
192192

193193
// Badge: Reset

WordPress/Classes/Utility/ZendeskUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class ZendeskUtils: NSObject, ZendeskUtilsProtocol {
307307
/// - post an NSNotification so the various indicators can be cleared.
308308
///
309309
static func pushNotificationRead() {
310-
UIApplication.shared.applicationIconBadgeNumber -= unreadNotificationsCount
310+
UNUserNotificationCenter.current().setBadgeCount(UIApplication.shared.applicationIconBadgeNumber - unreadNotificationsCount)
311311
unreadNotificationsCount = 0
312312
saveUnreadCount()
313313
postNotificationRead()

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Gridicons
88
import UIKit
99
import WordPressUI
1010
import SwiftUI
11+
import UserNotifications
1112

1213
/// The purpose of this class is to render the collection of Notifications, associated to the main
1314
/// WordPress.com account.
@@ -1720,7 +1721,7 @@ private extension NotificationsViewController {
17201721
func resetApplicationBadge() {
17211722
// These notifications are cleared, so we just need to take Zendesk unread notifications
17221723
// into account when setting the app icon count.
1723-
UIApplication.shared.applicationIconBadgeNumber = ZendeskUtils.unreadNotificationsCount
1724+
UNUserNotificationCenter.current().setBadgeCount(ZendeskUtils.unreadNotificationsCount)
17241725
}
17251726
}
17261727

WordPress/Classes/ViewRelated/System/WPTabBarController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ - (void)updateNotificationBadgeVisibility
356356
}
357357

358358
// Discount Zendesk unread notifications when determining if we need to show the notificationsTabBarImageUnread.
359+
#pragma clang diagnostic push
360+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
359361
NSInteger count = [[UIApplication sharedApplication] applicationIconBadgeNumber] - ObjCBridge.unreadNotificationsCount;
362+
#pragma clang diagnostic pop
363+
360364
if (count > 0 || ![self welcomeNotificationSeen]) {
361365
notificationsTabBarItem.image = self.notificationsTabBarImageUnread;
362366
notificationsTabBarItem.accessibilityLabel = NSLocalizedString(@"Notifications Unread", @"Notifications tab bar item accessibility label, unread notifications state");

0 commit comments

Comments
 (0)