PushNotifications.Server.AspNetCore 1.3.38-pre

This is a prerelease version of PushNotifications.Server.AspNetCore.
dotnet add package PushNotifications.Server.AspNetCore --version 1.3.38-pre                
NuGet\Install-Package PushNotifications.Server.AspNetCore -Version 1.3.38-pre                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PushNotifications.Server.AspNetCore" Version="1.3.38-pre" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PushNotifications.Server.AspNetCore --version 1.3.38-pre                
#r "nuget: PushNotifications.Server.AspNetCore, 1.3.38-pre"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PushNotifications.Server.AspNetCore as a Cake Addin
#addin nuget:?package=PushNotifications.Server.AspNetCore&version=1.3.38-pre&prerelease

// Install PushNotifications.Server.AspNetCore as a Cake Tool
#tool nuget:?package=PushNotifications.Server.AspNetCore&version=1.3.38-pre&prerelease                

PushNotifications.Server

Version Downloads

Server-side .NET library for sending push notifications to Apple Push Notification Service (APNS) and Google's Firebase Cloud Messaging (FCM).

Download and Install PushNotifications

This library is available on NuGet: https://www.nuget.org/packages/PushNotifications.Server Use the following command to install PushNotifications.Server using NuGet package manager console:

PM> Install-Package PushNotifications.Server

You can use this library in any .NET project which is compatible to .NET Standard 2.0 and higher.

ASP.NET Core Integration

For a smooth integration with ASP.NET Core projects, use following NuGet package: https://www.nuget.org/packages/PushNotifications.Server.AspNetCore Use the following command to install PushNotifications.Server.AspNetCore using NuGet package manager console:

PM> Install-Package PushNotifications.Server.AspNetCore

You can use this library in any ASP.NET Core project which is compatible to .NET Core 3.1 and higher.

Configure using appsettings.json

API Usage

The following sections document basic use cases of this library. The following code excerpts can also be found in the sample applications.

Cross-Platform Push Notifications

The goal of cross-platform push notification is to provide an abstracted request/response model in order to serve all unterlying platforms. PushNotificationClient is the implementation class of such a cross-platform push notification client. In order to create a new instance of PushNotificationClient, you have to create an instance of FcmClient and ApnsClient and pass it into PushNotificationClient.

var pushNotificationClient = new PushNotificationClient(fcmClient, apnsClient);
Sending PushRequests to all platforms

Cross-platform push requests are abstracted using class PushRequest. Create a new PushRequest and send it using the SendAsync method of PushNotificationClient.

var pushRequest = new PushRequest
{
    Content = new PushContent
    {
        Title = "Test Message",
        Body = $"Message @ {DateTime.Now}",
        CustomData = new Dictionary<string, string>
        {
            { "key", "value" }
        }
    },
    Devices = pushDevices
};

var pushResponse = await this.pushNotificationClient.SendAsync(pushRequest);
APNS Push Notifications (iOS / Apple)

Sending push notifications to iOS devices is pretty easy. Create a new instance of ApnsClient.

IApnsClient apnsClient = new ApnsClient(apnsJwtOptions);

Then, create an ApnsRequest with some title and body and send it out using SendAsync method.

var apnsRequest = new ApnsRequest(ApplePushType.Alert)
    .AddToken(token)
    .AddAlert("Test Message", $"Message @ {DateTime.Now}")
    .AddCustomProperty("key", "value");

var apnsResponse = await this.apnsClient.SendAsync(apnsRequest);
FCM Push Notifications (Android / Google)

In order to send FCM push notifications, you have to create a new instance of FcmClient. FcmClient requires an instance of FcmOptions, which contains the FCM configuration parameters which can be found on http://firebase.google.com. You can either create a FcmOptions manually (new FcmOptions{ ... }) or by binding from a appsettings.json file. See sample projects for more info.

This library supports both, the old "legacy" FcmClient as well as the new "v1" FcmClient. Check the firebase migration documentations before before selecting one or the other.

Sending Push Notifications using FcmClient (HTTP v1 API)
IFcmClient fcmClient = new FcmClient(fcmOptions);

Create a new FcmRequest and send it using the SendAsync method of FcmClient.

var fcmRequest = new FcmRequest()
{
    Message = new Message
    {
        Token = token,
        Notification = new Notification
        {
            Title = "Test Message",
            Body = $"Message @ {DateTime.Now}",
        },
        Data = new Dictionary<string, string>
        {
            { "key", "value" }
        },
    },
    ValidateOnly = false,
};

var fcmResponse = await this.fcmClient.SendAsync(fcmRequest);
Sending Push Notifications using FcmClient (Legacy HTTP API)

All legacy FCM client related code can be found in namespace PushNotifications.Server.Google.Legacy. The way the legacy FcmClient works is similar to the v1 FcmClient. The main differences can be found in the FcmOptions as well as in the request/response model.

IFcmClient fcmClient = new FcmClient(fcmOptions);

Create a new FcmRequest and send it using the SendAsync method of FcmClient.

var fcmRequest = new FcmRequest()
{
    To = token,
    Notification = new FcmNotification
    {
        Title = "Test Message",
        Body = $"Message @ {DateTime.Now}",
    },
    Data = new Dictionary<string, string>
    {
        { "key", "value" }
    },
};

var fcmResponse = await this.fcmClient.SendAsync(fcmRequest);

Handling Notification Responses from APNs https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns

Firebase Cloud Messaging HTTP protocol https://firebase.google.com/docs/cloud-messaging/http-server-ref

Contribution

Contributors welcome! If you find a bug or you want to propose a new feature, feel free to do so by opening a new issue on github.com.

License

This project is Copyright © 2021 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.38-pre 116 6/22/2024
1.3.36-pre 639 5/29/2023
1.3.35 6,485 12/31/2022
1.3.33-pre 663 12/31/2022
1.3.32-pre 637 10/1/2022
1.3.31-pre 696 8/15/2022
1.3.25 14,691 6/24/2022
1.3.23-pre 688 4/26/2022
1.3.22-pre 702 1/9/2022
1.3.21 1,286 1/6/2022
1.3.19-pre 736 12/16/2021
1.3.18-pre 702 11/11/2021
1.3.16 10,610 10/27/2021
1.3.14-pre 947 10/2/2021
1.3.12-pre 807 10/1/2021
1.3.0-pre 788 9/23/2021
1.2.11-pre 742 9/21/2021
1.2.10 907 9/13/2021
1.2.8-pre 777 8/30/2021
1.2.4 9,700 8/29/2021
1.2.2-pre 731 8/25/2021
1.1.13-pre.11 186 8/21/2021
1.1.11 2,642 8/17/2021
1.1.9-pre 741 8/17/2021
1.1.6-pre 751 8/17/2021
1.0.21227.2 903 8/15/2021
1.0.21226.1-pre 795 8/14/2021
1.0.21220.11-pre 822 8/8/2021
1.0.21220.8 2,425 8/8/2021
1.0.21220.6-pre 758 8/8/2021
1.0.21220.5 895 8/8/2021
1.0.21220.3-pre 752 8/8/2021

1.0.0
- Initial release