Skip to content

Instantly share code, notes, and snippets.

@tomcurran
Created February 14, 2023 11:06
Show Gist options
  • Save tomcurran/39009e9aa59ceea5869ec61a4e7bc5bc to your computer and use it in GitHub Desktop.
Save tomcurran/39009e9aa59ceea5869ec61a4e7bc5bc to your computer and use it in GitHub Desktop.
Firebase Messaging Test
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FirebaseAdmin" Version="2.3.0" />
</ItemGroup>
</Project>
using FirebaseAdmin;
using FirebaseAdmin.Messaging;
using Google.Apis.Auth.OAuth2;
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile("service-account.json"),
});
var registrationTokens = new List<string>()
{
"REGISTRATION_TOKEN_1",
};
var message = new MulticastMessage()
{
Tokens = registrationTokens,
Data = new Dictionary<string, string>()
{
{ "title", "Notification title test" },
{ "subtitle", "Notification subtitle test" },
},
};
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment