Firebase InstanceID

Aug 24, 2021 Swift

Firebase InstanceID token Deprecated

Firebase InstanceID.instanceID().token() method is deprecated in AppDelegate.swift

When we updated the pod file of the firebase InstantID was been depreciated .  As the pod file gets updated the appdelegate gives the Capacitor error as No such module ‘FirebaseInstanceID’ due this can fixed by removing the import FirebaseInstanceID

 

import FirebaseInstanceID

 

Comment or remove the above code in the AppDelegate

When you implement the Firebase Cloud messaging we had the FirebaseInstanceID in the package order for FCM token but it has been depreciated

firebase instance id get token deprecated


Initially the code which we used was

 

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    Messaging.messaging().apnsToken = deviceToken

    InstanceID.instanceID().instanceID { (result, error) in

        if let error = error {

           print("Error fetching remote instance ID: (error)")

        } else if let result = result {

            NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)

        }

    }

}

 

As we update the Pod file the Firebase messaging gives the Direct FCM token . Change the below code in the AppDelegate.swift file 

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    Messaging.messaging().apnsToken = deviceToken

    Messaging.messaging().token { (token, error) in

        if let error = error {

         print("Error fetching remote instance ID: (error)")

            NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)

        } else if let token = token {

            NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: token)

        }

    }

}

As If any queries or question please feel free to ask  them in comment below.

Index