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.
I found out that one absolutely need to set a body as follows:
That way, my notifications show off back again.