I have already push the GCM
message to google server using asp .net
in following method,
GCM Push Notification with Asp.Net
Now i have planned upgrade to FCM
method, anyone have idea about this or developing this in asp .net
let me know..
2019 Update
There's a new .NET Admin SDK that allows you to send notifications from your server. Install via Nuget
Install-Package FirebaseAdmin
You'll then have to obtain the service account key by downloading it by following the instructions given here, and then reference it in your project. I've been able to send messages by initializing the client like this
using FirebaseAdmin; using FirebaseAdmin.Messaging; using Google.Apis.Auth.OAuth2; ... public class MobileMessagingClient : IMobileMessagingClient { private readonly FirebaseMessaging messaging; public MobileMessagingClient() { var app = FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile("serviceAccountKey.json").CreateScoped("https://www.googleapis.com/auth/firebase.messaging")}); messaging = FirebaseMessaging.GetMessaging(app); } //... }
After initializing the app you are now able to create notifications and data messages and send them to the devices you'd like.
private Message CreateNotification(string title, string notificationBody, string token) { return new Message() { Token = token, Notification = new Notification() { Body = notificationBody, Title = title } }; } public async Task SendNotification(string token, string title, string body) { var result = await messaging.SendAsync(CreateNotification(title, body, token)); //do something with result }
..... in your service collection you can then add it...
services.AddSingleton<IMobileMessagingClient, MobileMessagingClient >();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With