2016-12-30 42 views
0

我最近切换到未通知以及与此升级代码上来:当切换到未通知,没有通知不再显示出来

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

我发现一个绝对需要设置一个机构如下:

content.body = "a body" 

这样一来,我的通知炫耀回来。