Does NotificationServiceExtension work with local notifications?

186 Views Asked by At

I created a small test project, enabled push notifications and remote notifications and added the template NotificationServiceExtension. When the notification is shown, the title isn't modified as the template would suggest, nor can I attach the debugger to the extension on the simulator.

The notification content has the mutable-content flag set properly, so I would expect it to be called.

{
  "aps": {
    "alert": {
      "title": "Notification Title",
      "body": "Notification Body"
    },
    "badge": 0,
    "mutable-content": 1,
    "sound": "default",
    "category": "richMessage"
  }
}

The code I'm using to build the notification:

guard let jsonResult = convertToDictionary(text: incomingData),
            let apsData = jsonResult["aps"] as? [String: Any],
            let alert = apsData["alert"] as? [String: String],
            let title = alert["title"],
            let body = alert["body"],
            let category = apsData["category"] as? String else { return }

        let localNotification = UNMutableNotificationContent()
        localNotification.title = title
        localNotification.body = body
        localNotification.categoryIdentifier = category

        let identifier = "SurveyIdentifier"
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
        let request = UNNotificationRequest(identifier: identifier, content: localNotification, trigger: trigger)
        UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
0

There are 0 best solutions below