5
votes

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?

4

4 Answers

2
votes

Use CorePush lib

It's very lightweight. I use it across all my projects to send Firebase Android and Apple iOS push notifications. Useful links:

  1. NuGet package
  2. Documentation

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);
1
votes

You need To make a POST request to https://fcm.googleapis.com/fcm/send with the following parameters Header

  • Authorization: key=YOUR_SERVER_KEY
  • Content-Type: 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

0
votes

You can use any cloud solutions for this case, like Azure Notification Hub.

You can check the documentation and configure your app with Notification Hub. With default configuration you will be able to broadcast your notification to all registered devices.

But in your case you need to send a notification to a specific device. In this case you need to use tags. When you register the device with Notification Hub register it with an unique id. So when you send a notification send it with same unique id as tag and it will received by that device only.

0
votes

You can use Pusher. It is a platform which simplifies working with push notifications. Currently it supports Android, iOS and channel-based notifications and, in my view, it's easy to configure than Azure Notifications or Amazon SNS.