Skip to content

Azure Push Notifications

Shiny.Push.AzureNotificationHubsNuGet package Shiny.Push.AzureNotificationHubs

Azure Notification Hubs provides tag-based targeting, templates, and enterprise-scale push management.

services.AddPushAzureNotificationHubs<MyPushDelegate>(
"Endpoint=sb://your-hub.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=your-key",
"your-hub-name"
);
#if ANDROID
services.AddPushAzureNotificationHubs<MyPushDelegate>(
"your-connection-string",
"your-hub-name",
new FirebaseConfig(
UseEmbeddedConfiguration: false,
AppId: "your-app-id",
SenderId: "your-sender-id",
ProjectId: "your-project-id",
ApiKey: "your-api-key"
)
);
#else
services.AddPushAzureNotificationHubs<MyPushDelegate>(
"your-connection-string",
"your-hub-name"
);
#endif

Use IPushInstallationEvent to modify the Azure Notification Hubs installation before it’s sent.

public class MyInstallationEvent : IPushInstallationEvent
{
public Task OnBeforeSend(Installation installation)
{
// Add custom tags
installation.Tags ??= new List<string>();
installation.Tags.Add("custom-tag");
// Add templates
installation.Templates ??= new Dictionary<string, InstallationTemplate>();
installation.Templates["myTemplate"] = new InstallationTemplate
{
Body = "{\"data\":{\"message\":\"$(message)\"}}"
};
return Task.CompletedTask;
}
}