While switching to UNNotification, no notification shows up anymore

79 views Asked by At

I recently switched to UNNotification and came up with this upgraded code:

   let content = UNMutableNotificationContent()
   content.title =  " \(story.title)"
   content.userInfo = ["Story.link": story.link, "Story.type": "HotNews"]

   let request = UNNotificationRequest(identifier: "NEW", content: content, trigger: nil)

   UNUserNotificationCenter.current().add(request) { error in

        if let error = error {
            //handle eror here
            print("*** Error presentHotNewsNotification(): \(error) (\(story.dumpProperties()))")
        }
        else {
            story.notified = true
            //story.saveContext
            print("presentHotNewsNotification() for story \(story.dumpProperties())")
        }
    }

While I see the pending notification with that code…

let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests { requests in
    for request in requests {
        print(request)
    }
}

…no notification shows up on the iPhone (or simulator) and no error are set.

1

There are 1 answers

0
Stéphane de Luca On BEST ANSWER

I found out that one absolutely need to set a body as follows:

 content.body = "a body"

That way, my notifications show off back again.