代码之家  ›  专栏  ›  技术社区  ›  RJB

未调用Swift DidReceiveEmotentification()Firebase

  •  0
  • RJB  · 技术社区  · 5 年前

    在广泛阅读了这篇文章之后,我找不到解决方案。我正在从Firebase向我的ios应用程序发送云消息,但根本没有调用DidReceiveEmotentification()方法,无论应用程序在前台还是后台都不会调用。我试着从firebase控制台发送邮件,也试着从使用主题的邮递员那里发送邮件,但两者都不起作用。我已经在应用程序中集成了Firebase,并将证书上传到Firebase,控制台中没有错误。只是通知不来?我还添加了云消息功能。

    以下是我在appDelegate中所做的(来自Firebase教程):

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
    
            FirebaseApp.configure()
    
    
    
            if #available(iOS 10.0, *) {
              // For iOS 10 display notification (sent via APNS)
              UNUserNotificationCenter.current().delegate = self
    
              let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
              UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
            } else {
              let settings: UIUserNotificationSettings =
              UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
              application.registerUserNotificationSettings(settings)
            }
    
            application.registerForRemoteNotifications()
    
            Messaging.messaging().delegate = self
    
            return true
        }
    
    
        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
          // If you are receiving a notification message while your app is in the background,
          // this callback will not be fired till the user taps on the notification launching the application.
          // TODO: Handle data of notification
    
          // With swizzling disabled you must let Messaging know about the message, for Analytics
          // Messaging.messaging().appDidReceiveMessage(userInfo)
    
          // Print message ID.
          if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
          }
    
          // Print full message.
          print(userInfo)
        }
    
        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                         fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
          // If you are receiving a notification message while your app is in the background,
          // this callback will not be fired till the user taps on the notification launching the application.
          // TODO: Handle data of notification
    
          // With swizzling disabled you must let Messaging know about the message, for Analytics
          // Messaging.messaging().appDidReceiveMessage(userInfo)
    
          // Print message ID.
          if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
          }
    
          // Print full message.
          print(userInfo)
    
          completionHandler(UIBackgroundFetchResult.newData)
        }
    
    0 回复  |  直到 5 年前