How to fix this error message "Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token"

Viewed 1532

I'm using ionic 4 with FCM to get notifications, everything works well on android but not on iOS. I'm facing this message on xcode console

"5.7.0 - [Firebase/Messaging][I-FCM002023] The object does not respond to -messaging:didReceiveRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token"

3 Answers

The message basically means that your FIRMessagingDelegate should implement the following method to be able to receive fcmToken by Firebase. fcmToken is usually used as a recipient identificator, i.e. to who you want send messages

- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken;

For example, you have a FirebaseMessagingManager class that works with Firebase Messaging then you could implement it in the following way:

#import <Foundation/Foundation.h>
#import <Firebase/Firebase.h>

@interface FirebaseMessagingManager : NSObject<MessagingDelegate>

- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
    NSLog(@"FCM registration token: %@", fcmToken);
}

@end 

Add this to method to your appdelegate.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 
   // let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
    UserDefaults.standard.set(deviceToken, forKey: "devToken")
    UserDefaults.standard.set(deviceToken, forKey: "devTokenString")

After going through the bugs opened on this issue I found the solution for IOS 12+. You simply need to add the following lines to your config.xml under the ios section:

<config-file parent="UIBackgroundModes" target="*-Info.plist">
<array>
    <string>remote-notification</string>
</array>

You can read more here: cordova-plugin-firebase Issue 788

Also don't forget to request notification permissions by calling Firebase.grantPermission();

Related