【问题标题】:While switching to UNNotification, no notification shows up anymore切换到 UNNotification 时,不再显示通知
【发布时间】:2016-12-30 19:59:10
【问题描述】:

我最近切换到 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(或模拟器)上没有显示通知,也没有设置错误。

【问题讨论】:

    标签: notifications swift3 ios10 unnotificationrequest


    【解决方案1】:

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

     content.body = "a body"
    

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

    【讨论】:

      猜你喜欢
      • 2018-08-15
      • 2018-12-19
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多