0

我最近切换到 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())")
        }
    }

当我看到带有该代码的待处理通知时……</p>

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

…iPhone(或模拟器)上没有显示通知,也没有设置错误。

4

1 回答 1

0

我发现绝对需要如下设置一个主体:

 content.body = "a body"

这样,我的通知就会再次显示出来。

于 2017-01-01T21:34:51.003 回答