AlphaOmega.PushSharp
4.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AlphaOmega.PushSharp --version 4.1.1
NuGet\Install-Package AlphaOmega.PushSharp -Version 4.1.1
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="AlphaOmega.PushSharp" Version="4.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlphaOmega.PushSharp" Version="4.1.1" />
<PackageReference Include="AlphaOmega.PushSharp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AlphaOmega.PushSharp --version 4.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AlphaOmega.PushSharp, 4.1.1"
#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.
#:package AlphaOmega.PushSharp@4.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AlphaOmega.PushSharp&version=4.1.1
#tool nuget:?package=AlphaOmega.PushSharp&version=4.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PushSharp v4.1
PushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS HTTP/2), Android/Chrome (FCM V1), HuaWay, Windows/Windows Phone, Amazon (ADM) and Blackberry devices!
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 Settings.Instance.ApnsDeviceTokens)
{
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 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();
HuaWay Sample Usage
Here is how you would send a HuaWay notification:
var clientSecret = "{ClientSecret}";
var projectId = "{ProjectId}";
var applicationId = "{ApplicationId}";
var config = new HuaWayConfiguration(clientSecret, projectId, applicationId);
var broker = new HuaWayServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
};
broker.OnNotificationSucceeded += (notification) => Console.WriteLine ("Notification Sent!");
broker.Start();
foreach(var regId in Settings.Instance.HuaWayRegistrationIds)
{
var notification = new HuaWayNotification();
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- 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.0 - Complete Rewrite, New API, see project site for more info