【发布时间】:2022-01-15 21:45:53
【问题描述】:
我现在使用 FirebaseNotifications 在我的应用中集成了推送通知。为此,我使用 NotificationServiceExtension 进行处理(CoreData,...)和常用方法,例如 AppDelegate 中的 didReceiveRemoteNotification、willPresent 或 didReceive。
内容的处理和推送通知的显示在应用程序的所有状态下都能完美运行 - 在后台和前台。
如果应用程序在前台或后台,但没有被杀死,点击推送通知也可以,并且调用 didReceive 方法,我可以导航到所需的内容。
如果应用程序被完全终止,几秒钟后点击推送通知会启动应用程序,但不会调用通常的启动屏幕(启动屏幕)并且不会发生其他任何事情 - 应用程序保持在 白色屏幕。
起初我怀疑我忘记调用completionHandler,但它们都被存储了,我没有在任何地方发现错误。
有人可以帮我吗,在哪里可能仍然存在启动屏幕,然后是 AppDelegate 和我的普通 ViewController 被调用的问题。
谢谢 - 这是我在 AppDelegate 中的代码。不幸的是,我没有日志,因为该应用程序必须被完全杀死,因此我在 Xcode 控制台中没有输出。
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
completionHandler(UIBackgroundFetchResult.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([[.alert, .badge, .sound]])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
defer {
completionHandler()
}
if response.actionIdentifier == "friends" {
print("Open button was pressed.")
// TODO: - Deep link to friends
}
completionHandler()
}
【问题讨论】:
标签: ios swift firebase push-notification notifications