web-dev-qa-db-fra.com

Firebase Messaging iOS 14

J'ai eu la configuration de la messagerie de Firebase Cloud dans mon application pendant un moment. J'ai récemment mis à jour l'un de mes appareils à iOS 14 et j'ai cessé de les recevoir sur ce périphérique. Un autre appareil avec iOS 13 les reçoit toujours. Je suis désolé si c'est un problème stupide haha, mais voici mon délégué de l'application:


let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
    
    var customerId = ""



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {


    application.registerForRemoteNotifications()

        FirebaseApp.configure()
        
        // Update this to your stripe PUBLISHABLE KEY
        STPPaymentConfiguration.shared().publishableKey = "private"
        
        let apiToken = "private"
        EasyPostApi.sharedInstance.setCredentials(apiToken, baseUrl: "https://api.easypost.com/v2/")
        STPTheme.default().accentColor = .red
        
        Messaging.messaging().delegate = self
        
        return true
    }

    // MARK: UISceneSession Lifecycle
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
      Messaging.messaging().apnsToken = deviceToken
        
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
      print(userInfo)
    print("test")
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print(userInfo)
        print("test")

      completionHandler(UIBackgroundFetchResult.newData)
    }
    
    func registerForPushNotifications() {
        // 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 })
        // For iOS 10 data message (sent via FCM
        Messaging.messaging().delegate = self
        InstanceID.instanceID().instanceID { (result, error) in
          if let error = error {
            print("Error fetching remote instance ID: \(error)")
          } else if let result = result {
            print("Remote instance ID token: \(result.token)")
          }
        }
        
    }

}

J'ai essayé d'envoyer des messages en utilisant la touche "Test" de la console Firebase et publie simplement un message comme Normal. Il s'inscrit correctement des notifications et après avoir vérifié les paramètres, il semble toujours correct.

10
Max S.

J'ai eu le même problème exact. Un correctif que j'ai trouvé pour l'instant était de désactiver la méthode Swizzling:

  • À votre application iOS info.plist, ajoutez FirebaseAppDelegateProxyEnabled et définissez-le sur false (valeur booléenne 0)

On dirait que vous avez déjà didRegisterForRemoteNotificationsWithDeviceToken Configuration, alors gardez cela comme ça.

J'espère que cela t'aides!

1
m179