UNNotificationServiceExtension not run

I'm trying to muck with my push notification using the service extension, but it doesn't appear to be running. The body of my method just looks like so:


override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    self.contentHandler = contentHandler
    bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

    guard let bestAttemptContent = bestAttemptContent else { return }

    bestAttemptContent.title = "new title here"
    contentHandler(bestAttemptContent)


So when iOS shows my alert, it should say 'new title here', but it still has what the payload sent. The payload looks like this. Any ideas what I've done wrong?


{
    "aps": {
        "alert": {
            "body": "The body",
            "title": "The title"
        },
        "category": "drawing-category",
        "mutable-content": 1
    }
}

I watched again WWDC16 / 707 On notification.


I notice thet in their definition of the payload they do not quote :; so it looks like :

{
    aps: {
        alert: {
            body: "The body",
            title: "The title"
        },
        category: "drawing-category",
        mutable-content: 1
    }
}


Could this be the reason ?



In didReceive, they create a newContent

let newContent = UNMutableNotificationContent()

which should be equivalent to the mutableCopy you create


What I do not understand is the need for :

self.contentHandler = contentHandler

No, putting quotes or not around the key of a JSON item doesn't change anything. As to the contentHandler, watch session 708 and you'll see that explained.

UNNotificationServiceExtension not run
 
 
Q