Amit Amit -4 years ago 292
iOS Question

Type 'NSNotification.Name?' has no member 'firInstanceIDTokenRefresh'

I'm using Firebase notifications in my iOS app with Swift and I recently updated Firebase Messaging to 2 from 1.2.3 and my code started breaking left right and center. I fixed most of the issues, but I'm stuck with this one.

Here is my portion of AppDelegate application function which causing me problem:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent


// [START add_token_refresh_observer]
// Add observer for InstanceID token refresh callback.
selector: #selector(self.tokenRefreshNotification),
name: .firInstanceIDTokenRefresh,
object: nil)
// [END add_token_refresh_observer]

return true

When I try to run my app, I get the following error:

Type 'NSNotification.Name?' has no member 'firInstanceIDTokenRefresh'

Has firInstanceIDTokenRefresh been renamed to something else?

Answer Source

It appears this notification has been replaced by a delegate method.

The Firebase Cloud Messaging documentation mentions how to monitor token generation:

Monitor token generation

To be notified whenever the token is updated, supply a delegate conforming to the FIRMessagingDelegate protocol. The following example registers the delegate and adds the proper delegate method:

func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    print("Firebase registration token: \(fcmToken)")


The docs also mention that the notification can still be used, it's now called Notification.Name.MessagingRegistrationTokenRefreshed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download