Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Firebase Messaging: What is kGCMMessageIDKey?

I'm trying to implement chat with Google Firebase. I'm following the tutorials but I cannot continue because an undeclared variable is being used and I cannot find its origin anywhere. The variable is called kGCMMessageIDKey.

It is being used first in here as:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

  if (userInfo[kGCMMessageIDKey]) {

    NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  }

In the sample project, kGCMMessageIDKey is declared in the AppDelegate as

NSString *const kGCMMessageIDKey = @"gcm.message_id";.

I have a feeling that this is a constant I should obtain from the Firebase dashboard but I cannot find any corresponding ID there either.

like image 790
Sam Avatar asked Jan 07 '18 20:01

Sam


People also ask

What is Sender ID in Firebase?

A sender ID: set in the code of your app. Android Studio uses automatically the Sender ID of your Firebase Project. If you are still using GCM, you have probably set manually the sender ID in the code of your app. The sender ID identifies your app to Firebase Cloud Messaging when it asks for a token.

What is FCM token in iOS?

By default, the FCM SDK generates a registration token for the client app instance on app launch. Similar to the APNs device token, this token allows you to send targeted notifications to any particular instance of your app.

What is difference between APNs and FCM?

Support for multiple platformsAPNs and WNS do not support multiple platforms. They are designed to work with their native platforms. But, FCM supports multiple platforms such as Android and iOS and even supports Chrome web apps.

What is Your_collapse_key in FCM?

FCM allows a maximum of four different collapse keys per device to be used by the app server at any given time. In other words, the FCM connection server can simultaneously store four different collapsible send-to-sync messages per device, each with a different collapse key.


1 Answers

The value should be the unique id for the message and should match the message_id parameter for the message that you'd see while interacting with Firebase Cloud Messaging APIs. You can also use that value to reference the message when using the FCM API/services from the device.

Yes, it seems that you either need to paste that constant declaration into your code, or replace it with @"gcm.message_id". The value does not seem significant and this code snippet is mainly for debugging.

I would encourage you to set a breakpoint in didReceiveRemoteNotification and examine the contents of userInfo to familiarize yourself with the message payload and the various attributes available to you from both FCM and iOS. When the breakpoint is hit, type the following into the debugger:

(lldb) po userInfo
like image 160
Adam Kaplan Avatar answered Oct 20 '22 19:10

Adam Kaplan