NotificationService is not called

I have read through many forums but haven't found a solution for myself. When sending a notification, my NotificationService is not being called. I added it exactly as described in the official Apple tutorial and tried adding it again following other tutorials. Nothing helped. I haven't made any changes to it; it is in the same form as it is automatically created. Here it is:

import UserNotifications

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 {
            // Modify the notification content here...
            bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
            
            contentHandler(bestAttemptContent)
        }
    }
    
    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }
}

It does not print anything or hit any breakpoints. The notification payload looks like this:

{
    "Simulator Target Bundle": "my.bundle",
    "aps": {
        "alert": {
            "title": "Its title",
            "body": "Very nice text"
        },
        "sound": "default",
        "category": "CustomSamplePush",
        "mutable-content": 1
    }
}

Things I've tried:

  • Ensured the minimum version matches that of the application.
  • Configured info.plist, including UNNotificationExtensionCategory.
  • Ensured "Copy Only When Installed" is unchecked.

The Content extension works. However, prints and breakpoints are also not working.

My app was created years ago. NotificationService used to run as expected. But recently I found out that it is not called any more. I've done the same research and tried everything above and still can't make it to work as before. This is so frustrated!

NotificationService is not called
 
 
Q