AlphaOmega.PushSharp
4.1.2
See the version list below for details.
dotnet add package AlphaOmega.PushSharp --version 4.1.2
NuGet\Install-Package AlphaOmega.PushSharp -Version 4.1.2
<PackageReference Include="AlphaOmega.PushSharp" Version="4.1.2" />
<PackageVersion Include="AlphaOmega.PushSharp" Version="4.1.2" />
<PackageReference Include="AlphaOmega.PushSharp" />
paket add AlphaOmega.PushSharp --version 4.1.2
#r "nuget: AlphaOmega.PushSharp, 4.1.2"
#:package AlphaOmega.PushSharp@4.1.2
#addin nuget:?package=AlphaOmega.PushSharp&version=4.1.2
#tool nuget:?package=AlphaOmega.PushSharp&version=4.1.2
PushSharp v4.1
PushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS HTTP/2), Android/Chrome (FCM V1), Huawei (HMS), Windows/Windows Phone, Amazon (ADM) and Blackberry devices!
Improvements:
- Added Apple APNS HTTP/2 support (New version)
- Added Firebase Cloud Messaging V1 support (New version)
- Added Huawei HMS V1 (New) [V2 in progress...]
- Changed assembly signing key file for all assemblies. (PublicKeyToken=a8ac5fc45c3adb8d)
- Added PE file signing. (S/N: 00c18bc05b61a77408c694bd3542d035)
- Added CI/CD pipelines
Sample Usage
APNS HTTP/2 Sample usage
var environment = ApnsSettings.ApnsServerEnvironment.Production;
var p8CertificatePath = "{P8CertificateFilePath}";
var p8CertificatePassword = "{P8CertificatePassword}";
var keyId = "{KeyId}";
var teamId = "{TeamId}";
var bundleId = "{com.company.appName}";
var settings = new ApnsSettings(
environment,
p8CertificatePath,
p8CertificatePassword,
keyId)
{
AppBundleId = bundleId,
};
var config = new ApnsConfiguration(settings);
var broker = new ApnsServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
};
broker.OnNotificationSucceeded += (notification) =>
{
};
broker.Start();
foreach(var dt in MY_DEVICE_TOKEN_IDS)
{
broker.QueueNotification(new ApnsNotification
{
DeviceToken = dt,
Payload = JObject.Parse("{ \"aps\" : { \"alert\" : \"I want cookie\" } }")
});
}
broker.Stop();
Firebase HTTP v1 Sample Usage
Here is how you would send a Firebase HTTP v1 notification:
var projectId = "{ProjectId}";
var privateKey = "{PrivateKey}";
var clientEmail = "{ClientEmail}";
var tokenUri = "{TokenUri}";
var settings = new FirebaseSettings(projectId, privateKey, clientEmail, tokenUri);
// var settings = JsonConvert.DeserializeObject<FirebaseSettings>("{Firebase.ServiceAccount.json}");
var config = new FirebaseConfiguration(settings);
// Create a new broker
var broker = new FirebaseServiceBroker(config);
// Wire up events
broker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle (ex => {
// See what kind of exception it was to further diagnose
if (ex is GcmNotificationException notificationException) {
// Deal with the failed notification
var gcmNotification = notificationException.Notification;
var description = notificationException.Description;
Console.WriteLine ($"Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
} else if (ex is GcmMulticastResultException multicastException) {
foreach (var succeededNotification in multicastException.Succeeded) {
Console.WriteLine ($"Notification Succeeded: ID={succeededNotification.MessageId}");
}
foreach (var failedKvp in multicastException.Failed) {
var n = failedKvp.Key;
var e = failedKvp.Value;
Console.WriteLine ($"Notification Failed: ID={n.MessageId}, Desc={e.Description}");
}
} else if (ex is DeviceSubscriptionExpiredException expiredException) {
var oldId = expiredException.OldSubscriptionId;
var newId = expiredException.NewSubscriptionId;
Console.WriteLine ($"Device RegistrationId Expired: {oldId}");
if (!string.IsNullOrWhiteSpace (newId)) {
// If this value isn't null, our subscription changed and we should update our database
Console.WriteLine ($"Device RegistrationId Changed To: {newId}");
}
} else if (ex is RetryAfterException retryException) {
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
Console.WriteLine ($"Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
} else {
Console.WriteLine ("Notification Failed for some unknown reason");
}
// Mark it as handled
return true;
});
};
broker.OnNotificationSucceeded += (notification) => Console.WriteLine ("Notification Sent!");
// Start the broker
broker.Start();
foreach (var regId in MY_REGISTRATION_IDS) {
// Queue a notification to send
var notification = new FirebaseNotification();
notification.message.token = regId;
notification.message.data = JObject.Parse("{ \"somekey\" : \"I want cookie\" }");
broker.QueueNotification(notification);
}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
broker.Stop();
Huawei (HMS) Sample Usage
Here is how you would send a Huawei (HMS) notification:
var clientSecret = "{ClientSecret}";
var projectId = "{ProjectId}";
var applicationId = "{ApplicationId}";
var config = new HuaweiConfiguration(clientSecret, projectId, applicationId);
var broker = new HuaweiServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
};
broker.OnNotificationSucceeded += (notification) => Console.WriteLine ("Notification Sent!");
broker.Start();
foreach(var regId in MY_REGISTRATION_IDS)
{
var notification = new HuaweiNotification();
notification.Message.token = new String[] { regId };
notification.Message.data = JObject.Parse("{ \"somekey\" : \"I want cookie\" }");
broker.QueueNotification(notification);
}
broker.Stop();
You can read other sample usages on original author page: Redth PushSharp
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net48 is compatible. net481 was computed. |
-
- Newtonsoft.Json (>= 13.0.3)
- Portable.BouncyCastle (>= 1.9.0)
- System.Net.Http.WinHttpHandler (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
4.1.* - Updated APNS for HTTP/2 implementation, Updated Android FCM V1 implementation, Added Huawei (HMS), see project site for more info