setBadgeCount(_:withCompletionHandler:)
Updates the badge count for your app’s icon.
Declaration
func setBadgeCount(_ newBadgeCount: Int, withCompletionHandler completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)func setBadgeCount(_ newBadgeCount: Int) async throwsParameters
- newBadgeCount:
The new value to display.
- completionHandler:
The handler to execute after the update finishes. If the update fails, the system provides an error that contains additional information about the failure.
Discussion
Here’s an example that sets the badge count to a specific number.
let center = UNUserNotificationCenter.current()
do {
// Set the badge count to 3.
try await center.setBadgeCount(3)
} catch {
// Handle any errors.
}