我最近切换到UNNotification并提出了这个升级代码:
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())")
}
}
虽然我看到该代码的待处理通知......
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests { requests in
for request in requests {
print(request)
}
}
... iPhone(或模拟器)上没有显示通知,也没有设置错误。
答案 0 :(得分:0)
我发现绝对需要按如下方式设置正文:
content.body = "a body"
这样,我的通知再次显示出来。