【发布时间】:2021-05-18 13:36:30
【问题描述】:
在 willPresent 通知方法中,当应用程序处于前台状态时,我们会收到有效负载。 实际上,我想从 firebase 推送通知响应生成本地通知,但我不明白当应用程序处于后台和终止状态时调用了哪些委托方法。
【问题讨论】:
标签: swift firebase firebase-cloud-messaging
在 willPresent 通知方法中,当应用程序处于前台状态时,我们会收到有效负载。 实际上,我想从 firebase 推送通知响应生成本地通知,但我不明白当应用程序处于后台和终止状态时调用了哪些委托方法。
【问题讨论】:
标签: swift firebase firebase-cloud-messaging
您应该始终调用 willPresent 方法的 completionHandler 方法,正如 docs 中提到的那样:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .sound])
}
这样,即使在后台或终止状态下,您也可以处理通知。
【讨论】: