当应用程序位于前台且带有 Firebase 推送通知时没有通知

问题描述 投票:0回答:1

当应用程序处于后台时我会收到通知,但当应用程序处于前台时则不会收到通知。我完全按照这里所说的去做。我做错了什么?

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = response.notification.request.content.userInfo ... let sb = UIStoryboard(name: "Main", bundle: nil) let otherVC = sb.instantiateViewController(withIdentifier: "HomeVC") as! UITabBarController otherVC.selectedIndex = 2 UIApplication.shared.keyWindow?.rootViewController = otherVC; completionHandler([.banner, .badge, .sound]) }
    
swift firebase-cloud-messaging apple-push-notifications
1个回答
2
投票
// As we know, this method will be called when app received push notifications in foreground func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { { // Play a sound to let the user know about the invitation. completionHandler(.sound) }
    
© www.soinside.com 2019 - 2024. All rights reserved.