7

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?

5 Answers 5

4

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);
3
  • 1
    THE samples and docs are rubbish of it doesnt even show you how to get tokens or nothing Sep 25, 2021 at 7:02
  • @csharpdude77 well they don't have to. The docs are for the library, not for the firebase or apn or Apple/Android push notification subscription.
    – Andrei
    Sep 25, 2021 at 16:02
  • @Andrei how to subscribe to topic using this package, how to create group using this package? Dec 22, 2021 at 12:48
1

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

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

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.

1
  • thx, too bad we have to pay for it for the enterprise usage :)
    – zlaayaa
    Oct 4, 2018 at 7:14
0

I’pretty late in this discussion, but it might still help someone having the same question:

  • Offline Push Notifications: We did this once as a combination of regular/online push notifications and local notifications. So, the idea is to synchronize the next N scheduled notifications to the client and then send local notifications directly on the client. Of course, tjis scenario does not work for all business cases.
  • Regular Push Notifications: We’re sending push requests using our own library, https://www.nuget.org/packages/PushNotifications.Server.AspNetCore/ which perfectly integrates with both, Android/FCM and Apple/APNS. Read the readme to get a first impression of the API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.