KnstNotify.Core 1.0.3-pre

This is a prerelease version of KnstNotify.Core.
There is a newer version of this package available.
See the version list below for details.
dotnet add package KnstNotify.Core --version 1.0.3-pre                
NuGet\Install-Package KnstNotify.Core -Version 1.0.3-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="KnstNotify.Core" Version="1.0.3-pre" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KnstNotify.Core --version 1.0.3-pre                
#r "nuget: KnstNotify.Core, 1.0.3-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 KnstNotify.Core as a Cake Addin
#addin nuget:?package=KnstNotify.Core&version=1.0.3-pre&prerelease

// Install KnstNotify.Core as a Cake Tool
#tool nuget:?package=KnstNotify.Core&version=1.0.3-pre&prerelease                

Build Status Board Status Nuget Nuget (with prereleases)

KnstNotify

A sender for Apple Push Notification(APN) and Firebase Cloud Message(FCM).

Reference: CorePush


Quick Start

APN

Register in Startup.cs ConfigureServices, for example :

services.AddApnConfig(new ApnConfig("{P8-PrivateKey}", "{P8-PrivateKeyId}", "{TeamId}", "{Topic}", ApnServerType.Development));
services.AddKnstNotify();

Create an apn payload : ApnPayload

ApnPayload apnPayload = new ApnPayload();
apnPayload.DeviceToken = "{deviceToken}";
apnPayload.Aps.Badge = 1;
apnPayload.Aps.Alert.Title = "title";
apnPayload.Aps.Alert.Subtitle = "subtitle";
apnPayload.Aps.Alert.Body = "body";
apnPayload.Aps.Sound = "default";
apnPayload.Aps.MutableContent = 1;
apnPayload.Aps.ContentAvailable = 1;

Send apn payload :

IApnSender apnSender = provider.GetRequiredService<IApnSender>();
ApnResult apnResult = await apnSender.SendAsync(apnPayload);

FCM

Register in Startup.cs ConfigureServices, for example :

services.AddFcmConfig(new FcmConfig("{ServerKey}"));
// or
services.AddFcmConfig(new FcmConfig("{ServerKey}", "{SenderId}"));
services.AddKnstNotify();

Create an fcm payload : FcmPayload

FcmPayload fcmPayload = new FcmPayload()
{
    DryRun = true,    // sandbox
    Data = new Dictionary<string, object>()
};
fcmPayload.To = "{deviceToken}";
fcmPayload.Data.Add("title", "title");
fcmPayload.Data.Add("image", "icon");
fcmPayload.Data.Add("message", "message");
fcmPayload.Data.Add("badge", "1");
fcmPayload.Data.Add("sound", "default");

Send fcm payload :

IFcmSender fcmSender = provider.GetRequiredService<IFcmSender>();
FcmResult fcmResult = await fcmSender.SendAsync(fcmPayload);

Multi Notifications

100 tokens for example :

IEnumerable<string> tokens = new string[100];

APN

IEnumerable<ApnPayload> apnPayloads = tokens.Select(token=>{
    ApnPayload apnPayload = new ApnPayload();
    apnPayload.DeviceToken = token;
    apnPayload.Aps.Badge = 1;
    apnPayload.Aps.Alert.Title = "title";
    apnPayload.Aps.Alert.Subtitle = "subtitle";
    apnPayload.Aps.Alert.Body = "body";
    apnPayload.Aps.Sound = "default";
    apnPayload.Aps.MutableContent = 1;
    apnPayload.Aps.ContentAvailable = 1;
    return apnPayload;
});
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads);

FCM

IEnumerable<FcmPayload> fcmPayloads = tokens.Select(token =>
{
    FcmPayload fcmPayload = new FcmPayload()
    {
        DryRun = true,
        Data = new Dictionary<string, object>()
    };
    fcmPayload.To = token;
    fcmPayload.Data.Add("title", "title");
    fcmPayload.Data.Add("image", "icon");
    fcmPayload.Data.Add("message", "message");
    fcmPayload.Data.Add("badge", "1");
    fcmPayload.Data.Add("sound", "default");
    return fcmPayload;
});
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads);

Support Multi Keys

APN Example :

// In Startup.cs ConfigureServices
services.AddApnConfig(new ApnConfig("{P8-PrivateKey-1}", "{P8-PrivateKeyId-1}", "{TeamId-1}", "{Topic-1}", HostEnvironment.IsDevelopment() ? ApnServerType.Development : ApnServerType.Production));
services.AddApnConfig(new ApnConfig("{P8-PrivateKey-2}", "{P8-PrivateKeyId-2}", "{TeamId-2}", "{Topic-2}", HostEnvironment.IsDevelopment() ? ApnServerType.Development : ApnServerType.Production));
services.AddKnstNotify();

// Usage
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads, sender => sender.Configs.First());

FCM Example :

// In Startup.cs ConfigureServices
services.AddFcmConfig(new FcmConfig("{ServerKey-1}"), HostEnvironment.IsDevelopment());
services.AddFcmConfig(new FcmConfig("{ServerKey-2}"), HostEnvironment.IsDevelopment());
services.AddKnstNotify();

// Usage
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads, sender => sender.Configs.First());
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.0.6 11,226 12/15/2020
1.0.5.1 490 5/20/2020
1.0.5 512 2/1/2020
1.0.4-pre 453 1/10/2020
1.0.3-pre 419 1/9/2020
1.0.2-pre 446 1/8/2020
1.0.1-pre 335 1/7/2020
1.0.0-pre 356 1/7/2020