【发布时间】:2018-03-26 20:34:03
【问题描述】:
我正在做一个安排本地通知并保存用户信息的应用程序。这部分没关系。
但是当应用程序关闭时,会出现通知,但是当用户单击时,该方法没有被调用,我无法处理 userInfo。
我发现有一种通过UNUserNotificationCenter 接收通知的新方法。但也不起作用。
这是我在 AppDelegate 中的实现:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let lNotification = UILocalNotification()
lNotification.userInfo = response.notification.request.content.userInfo
applicationWorker.manage(localNotification: lNotification)
}
有人帮我吗?我在这里看到了所有相关的问题,但没有找到任何东西。
谢谢!
编辑:
如果有人在寻找解决方案,我在didFinishLaunchingWithOptions 中添加了UNUserNotificationCenter.current().delegate = self,它成功了。
【问题讨论】:
-
@MarcusMenezes 我在
didFinishLaunchingWithOptions中添加了UNUserNotificationCenter.current().delegate = self,然后调用了方法。我希望它有帮助! -
tks @rafaela-lourenço
-
@RafaelaLourenço 很高兴您通过设置委托使其正常工作。这可以解释为什么该方法没有被调用! :)
标签: ios swift swift3 notifications uilocalnotification