I have Chat service in .NET Core Web API, handling chat messages through Signal R when clients are online.
Also, i have mobile clients (android/apple) and i need to handle messages sent when client is in offline mode. I am aware if clients are offline/online. So, when the client is offline, i want to send message to apple/android push notification server so it can notify the device about new message(s).
Which options do i have to connect net core Web API to android/apple push notification servers? Any experiences with sending client push notifications to mobile clients from .net service?
Overview. When important, time-sensitive events occur, inform your website users with push notifications you send from your server. In Safari 16 in macOS 13 or later, Safari supports web push — push notifications that use the cross-browser Push API, Notifications API, and Service Worker standards.
Although we often associate web push with desktop notifications, web push notifications can also appear on tablets and Android devices (Apple iOS does not support web push). The name “web” refers to the mechanism by which notifications are sent to a user's device via a web browser (e.g. Chrome, Safari).
For sending Notification to any android Device you can use two technology: 1) Push. 2) Pull. For Push Technology you can use GCM(Google cloud messaging). For Pull Technology you can make you application continuously keep on connecting to server and trying to fetch data if it is available from there.
It's very lightweight. I use it across all my projects to send Firebase Android and Apple iOS push notifications. Useful links:
The interface is very simple and minimalistic:
Send APN message:
var apn = new ApnSender(settings, httpClient);
await apn.SendAsync(notification, deviceToken);
Send FCM message:
var fcm = new FcmSender(settings, httpClient);
await fcm.SendAsync(deviceToken, notification);
You need To make a POST request to https://fcm.googleapis.com/fcm/send with the following parameters Header
key=YOUR_SERVER_KEY
Application/JSON
Body:
{
"to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",
"collapse_key" : "type_a",
"notification" : {
"body" : "First Notification",
"title": "Collapsing A"
},
"data" : {
"body" : "First Notification",
"title": "Collapsing A",
"key_1" : "Data for key one",
"key_2" : "Hellowww"
}
You can get your server Token from Firebase Console
. Also you need to set up APN in order for this to work on iOS.
You can find More info here
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