KnstNotify.Core 1.0.5.1

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

Install-Package KnstNotify.Core -Version 1.0.5.1
dotnet add package KnstNotify.Core --version 1.0.5.1
<PackageReference Include="KnstNotify.Core" Version="1.0.5.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KnstNotify.Core --version 1.0.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Build Status
Board Status
Nuget
Nuget (with prereleases)

ICON

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();

P8-PrivateKey(without newline) :
P8_PrivateKey

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.Add("Key1", "Value1");
apnPayload.Aps["Key2"] = "Value2";

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}", HostEnvironment.IsDevelopment()));
// or
services.AddFcmConfig(new FcmConfig("{ServerKey}", "{SenderId}", HostEnvironment.IsDevelopment()));
services.AddKnstNotify();

Create an fcm payload :
FcmPayload

FcmPayload fcmPayload = new FcmPayload()
{
    Data = new Dictionary<string, object>(),
    Notification = new Dictionary<string, object>()
};
fcmPayload.To = "{deviceToken}";
fcmPayload.Notification.Add("title", "title");
fcmPayload.Notification.Add("body", "body");
fcmPayload.Data.Add("Key1", "Value1");
fcmPayload.Data["Key2"] = "Value2";

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.Add("Key1", "Value1");
    apnPayload.Aps["Key2"] = "Value2";
    return apnPayload;
});
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads);

FCM

IEnumerable<FcmPayload> fcmPayloads = tokens.Select(token =>
{
    FcmPayload fcmPayload = new FcmPayload()
    {
        Data = new Dictionary<string, object>(),
        Notification = new Dictionary<string, object>()
    };
    fcmPayload.To = token;
    fcmPayload.Notification.Add("title", "title");
    fcmPayload.Notification.Add("body", "body");
    fcmPayload.Data.Add("Key1", "Value1");
    fcmPayload.Data["Key2"] = "Value2";
    return fcmPayload;
});
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads);

Support Multi Configs

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){ Name = "Config1" });
services.AddApnConfig(new ApnConfig("{P8-PrivateKey-2}", "{P8-PrivateKeyId-2}", "{TeamId-2}", "{Topic-2}", HostEnvironment.IsDevelopment() ? ApnServerType.Development : ApnServerType.Production){ Name = "Config2" });
services.AddKnstNotify();

// Usage
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads, sender => sender.Configs.Single(x => x.Name == "Config1"));

FCM Example :

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

// Usage
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads, sender => sender.Configs.Single(x => x.Name == "Config1"));

Build Status
Board Status
Nuget
Nuget (with prereleases)

ICON

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();

P8-PrivateKey(without newline) :
P8_PrivateKey

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.Add("Key1", "Value1");
apnPayload.Aps["Key2"] = "Value2";

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}", HostEnvironment.IsDevelopment()));
// or
services.AddFcmConfig(new FcmConfig("{ServerKey}", "{SenderId}", HostEnvironment.IsDevelopment()));
services.AddKnstNotify();

Create an fcm payload :
FcmPayload

FcmPayload fcmPayload = new FcmPayload()
{
    Data = new Dictionary<string, object>(),
    Notification = new Dictionary<string, object>()
};
fcmPayload.To = "{deviceToken}";
fcmPayload.Notification.Add("title", "title");
fcmPayload.Notification.Add("body", "body");
fcmPayload.Data.Add("Key1", "Value1");
fcmPayload.Data["Key2"] = "Value2";

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.Add("Key1", "Value1");
    apnPayload.Aps["Key2"] = "Value2";
    return apnPayload;
});
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads);

FCM

IEnumerable<FcmPayload> fcmPayloads = tokens.Select(token =>
{
    FcmPayload fcmPayload = new FcmPayload()
    {
        Data = new Dictionary<string, object>(),
        Notification = new Dictionary<string, object>()
    };
    fcmPayload.To = token;
    fcmPayload.Notification.Add("title", "title");
    fcmPayload.Notification.Add("body", "body");
    fcmPayload.Data.Add("Key1", "Value1");
    fcmPayload.Data["Key2"] = "Value2";
    return fcmPayload;
});
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads);

Support Multi Configs

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){ Name = "Config1" });
services.AddApnConfig(new ApnConfig("{P8-PrivateKey-2}", "{P8-PrivateKeyId-2}", "{TeamId-2}", "{Topic-2}", HostEnvironment.IsDevelopment() ? ApnServerType.Development : ApnServerType.Production){ Name = "Config2" });
services.AddKnstNotify();

// Usage
IEnumerable<ApnResult> apnResults = await apnSender.SendAsync(apnPayloads, sender => sender.Configs.Single(x => x.Name == "Config1"));

FCM Example :

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

// Usage
IEnumerable<FcmResult> fcmResults = await fcmSender.SendAsync(fcmPayloads, sender => sender.Configs.Single(x => x.Name == "Config1"));

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.5.1 63 5/20/2020
1.0.5 78 2/1/2020
1.0.4-pre 155 1/10/2020
1.0.3-pre 125 1/9/2020
1.0.2-pre 143 1/8/2020
1.0.1-pre 59 1/7/2020
1.0.0-pre 68 1/7/2020