当前景中的用户和应用重新安装时,不会调用willPresent和didReceive Notification委托

时间:2019-05-30 06:34:09

标签: ios swift push-notification firebase-cloud-messaging usernotifications

我已经实现了FirebaseCloudMessaging,当应用程序位于notifications中时却获得了Background,但是当我安装了全新的应用程序willPresentdidReceive通知{{1 }}在30到35分钟后仍未收到呼叫,它将开始呼叫。

只有当我通过删除旧版本安装应用程序时,这种情况才会发生。

这是我的代码,您可以检查我在哪里弄错了

delegate

感谢帮助

1 个答案:

答案 0 :(得分:0)

用此代码替换registerForNotification功能代码。可能会有帮助

UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (isAllow, error) in

            if isAllow {

                Messaging.messaging().delegate = self

            }

        }

        UIApplication.shared.registerForRemoteNotifications()

当用户允许通知时,将调用此委托方法

 func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {

        print(fcmToken)



    }

点击通知时

  func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        //when notification is tapped

    }

当应用程序处于前台时,将调用此方法

  func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

        //this method is called when notification is about to appear in foreground

        completionHandler([.alert, .badge, .sound]) // Display notification as

    }