FCM: Invalid Parameter, Token Reason For IOS

I'm integrating FCM into my iOS app. I'm receiving this error when sending token to my backend server:

Invalid parameter: Token Reason: iOS device tokens must be no more than 400 hexadecimal characters

And in my code, I'm sending FCM registration token to the server. Is this correct? or should I send device token instead? If so, what's the use of this FCM registration token for?

Need help on this.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
//Get FCM registration token
[[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
                                                    NSError * _Nullable error) {
    if (error != nil) {
        NSLog(@"Error fetching remote instance ID: %@", error);
    } else {
        NSLog(@"Remote instance ID token: %@", result.token);

        [UserDefaultUtility setDeviceToken:result.token];


#pragma mark - FCM delegate
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
// Note: This callback is fired at each app startup and whenever a new token is generated.

NSLog(@"FCM registration token: %@", fcmToken);
[UserDefaultUtility setDeviceToken:fcmToken];


I'm doing this on simulator, does it affect it?



This is likely an error with your backend.

The FCM Token is generated by Firebase, and Firebase alone handles the mappings between the FCM token and the iOS Device Token. Thus, when you use FCM, you only care about the FCM token so that is definitely what you should be sending. However, it seems that your backend, for some reason, is expecting an actual iOS Device token.

So to fix this error, you have to change your backend code (which you haven't provided so I can't help with), so that it is not expecting an actual iOS Device Token, but instead expects an FCM token.

Then, to "use FCM", you'd change your backend to stop directly interacting with Apple's push notification servers (or whatever other service you currently used that needed the actual iOS Device Token), and start interacting with the FCM APIs instead, using any of the methods listed in the docs. The FCM APIs would use the FCM Token to identify which device to send push notifications to.