Created
February 14, 2023 11:06
-
-
Save tomcurran/39009e9aa59ceea5869ec61a4e7bc5bc to your computer and use it in GitHub Desktop.
Firebase Messaging Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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