.NET Core Web API push to Apple/Android push notification servers
Asked Answered
B

5

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?

Blowzy answered 2/10, 2018 at 14:14 Comment(0)
D
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);
Diplomatist answered 29/11, 2018 at 0:25 Comment(3)
THE samples and docs are rubbish of it doesnt even show you how to get tokens or nothingPredial
@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.Diplomatist
@Diplomatist how to subscribe to topic using this package, how to create group using this package?Circumrotate
P
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

Pest answered 2/10, 2018 at 14:39 Comment(0)
A
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.

Aronoff answered 2/10, 2018 at 14:44 Comment(0)
T
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.

Thumbprint answered 2/10, 2018 at 15:16 Comment(1)
thx, too bad we have to pay for it for the enterprise usage :)Blowzy
B
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.
Barbarous answered 31/8, 2021 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.