How to Send GCM Messages Using C#

In my previous blog post, I mentioned how to send APNS messages using C#. In this post, I will do the same using GCM.

Sending a GCM message is very similar, but in this case we will use a different NuGet package. You will need to install the FirebaseAdmin NuGet package.

The first step of working with the FirebaseAdmin plugin is initializing the Firebase Application. This is done by calling the static create method on the FirebaseApp class.

How do you get that JSON file? The easiest way is to go to your Firebase application console. The URL for this will be something like https://console.firebase.google.com/. From there, you can navigate to Project settings.

Within Project settings, go to the Cloud Messaging tab.

From the Cloud Messaging tab, navigate to Google’s cloud configuration where you create a token and your .json file.

Now that you have your token and the code to create the app, you need to send a message. This is very similar to sending an APNS message. We call a send method with the contents of our message.

The code above will send a message to a device token. But how do we get a device token? That will be the subject of an upcoming blog post.

author avatar
Chad Michel Senior Software Architect
Chad is a lifelong Nebraskan. He grew up in rural Nebraska and now lives in Lincoln. Chad and his wife have a son and daughter.

Related posts