Skip to content

Sending Notifications

The INotificationManager provides methods to send, query, and cancel notifications.

INotificationManager notifications; // injected
// Simple notification
await notifications.Send(
title: "Hello",
message: "This is a notification"
);
// Full notification with all options
await notifications.Send(new Notification
{
Id = 1,
Title = "Order Shipped",
Message = "Your order #12345 has shipped!",
Channel = "Orders",
BadgeCount = 3,
Thread = "order-updates",
Payload = new Dictionary<string, string>
{
{ "orderId", "12345" },
{ "action", "shipped" }
}
});
PropertyTypeDescription
IdintUnique notification ID
Titlestring?Notification title
Messagestring?Notification body (required)
Channelstring?Channel identifier
PayloadIDictionary<string, string>Custom key/value data
BadgeCountint?App icon badge number
Threadstring?Thread ID for grouping
ScheduleDateDateTimeOffset?When to display
RepeatIntervalIntervalTrigger?Repeating schedule
GeofenceGeofenceTrigger?Location-based trigger
var pending = await notifications.GetPendingNotifications();
foreach (var notification in pending)
{
Console.WriteLine($"{notification.Id}: {notification.Title}");
}
// Get a specific notification
var notification = await notifications.GetNotification(1);
// Cancel a specific notification
await notifications.Cancel(1);
// Cancel by scope
await notifications.Cancel(CancelScope.All); // Everything
await notifications.Cancel(CancelScope.DisplayedOnly); // Only displayed notifications
await notifications.Cancel(CancelScope.Pending); // Only pending (scheduled/triggered)

Badge count management is platform-dependent.

// Check if badges are supported and set
var success = await notifications.TrySetBadge(5);
// Get current badge count
var (supported, count) = await notifications.TryGetBadge();
if (supported)
Console.WriteLine($"Badge: {count}");