【发布时间】:2020-06-04 23:29:56
【问题描述】:
我设置了以下本地通知:
let content = UNMutableNotificationContent()
content.title = "Some Title"
content.body = "Some text"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 20, repeats: false)
let request = UNNotificationRequest(identifier: "OneDay", content: content, trigger: trigger)
notificationCenter.add(request)
我已将以下内容添加到 AppDelegate
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Notification Tapped")
if response.notification.request.identifier == "OneDay" {
print("OneDay Notification Tapped")
}
completionHandler()
}
notificationCenter 已设置为:
let notificationCenter = UNUserNotificationCenter.current()
但是,上述打印语句都不起作用。显示通知,我点击它,应用程序被带到前台,但没有任何内容打印到控制台。
我在这里遗漏了什么吗?我已经在模拟器和设备中进行了测试。结果一样。
我正在使用 XCode 11.5,为 12.0 进行部署。
【问题讨论】:
标签: ios swift unusernotificationcenter