Push Notification Gets Removed From Notification Screen When Setting "badge" to 0

Push message on the lock-screen disappears in one specific instance.

In general the situation is as follows:

  • the application, upon starting up, sets the badge counter (i.e. notificationCenter.setBadgeCount(3))
  • the application is being sent to background
  • the screen is locked (it doesn't matter if it's turned on or not)
  • send a push message to the application and set the badge (in aps) to "0"

What happens:

  • the screen lights up (unless it's lit up already), the push is being displayed for a very short time and gets hidden.

Happens on iOS 18.1, 18.1.1, 18.2. If not setting badge in the aps keys it works correctly.

I've created a feedback report https://feedbackassistant.apple.com/feedback/16095572. I am able to reproduce the issue on a sample app 100% of the time :/

Answered by Engineer in 818014022

Thank you for the bug report and the sysdiagnose. The Location team will need to take a look at this.

Accepted Answer

Thank you for the bug report and the sysdiagnose. The Location team will need to take a look at this.

What is funny, though, is that "removing the badge" in the extension seems to fix the issue, at least temporarily.

If if remove the variable under "badge" (NSNumber) the notification seems to work. It's only the "zero" value that causes the issue.

I will update the ticket as well.

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?
    
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        
        if let bestAttemptContent = bestAttemptContent {
            if let badge = bestAttemptContent.badge, badge.intValue < 1 {
                bestAttemptContent.badge = nil
            }
            contentHandler(bestAttemptContent)
        }
        else {
            contentHandler(request.content)
        }
    }
Push Notification Gets Removed From Notification Screen When Setting "badge" to 0
 
 
Q