Skip to content

Commit 5243d71

Browse files
committed
Notification Hubs: add .NET SDK examples
1 parent fb663b4 commit 5243d71

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

articles/notification-hubs/browser-push.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,42 @@ The following examples show the registration request body for a native registrat
149149
}
150150
```
151151

152+
### .NET SDK
153+
154+
Create native registrations:
155+
156+
```csharp
157+
await notificationHubClient.CreateBrowserNativeRegistrationAsync(subscriptionInfo, tagSet);
158+
```
159+
160+
Create template registrations:
161+
162+
```csharp
163+
await notificationHubClient.CreateBrowserTemplateRegistrationAsync(subscriptionInfo, template, tagSet);
164+
```
165+
166+
Create browser installations:
167+
168+
```csharp
169+
var browserPushSubscription = new BrowserPushSubscription
170+
{
171+
Endpoint = "",
172+
P256DH = "",
173+
Auth = "",
174+
};
175+
176+
var browserInstallation = new BrowserInstallation
177+
{
178+
InstallationId = installationId,
179+
Tags = tags,
180+
Subscription = browserPushSubscription,
181+
UserId = userId,
182+
ExpirationTime = DateTime.UtcNow.AddDays(1),
183+
};
184+
185+
await notificationHubClient.CreateOrUpdateInstallationAsync(browserInstallation);
186+
```
187+
152188
## Send push notifications
153189

154190
After you [set credentials for browser push](#set-credentials) and [create registrations and installations](#create-registrations-and-installations) for the devices, you're ready to create push notifications. This section describes how to create a notification for a [direct send|](#create-direct-sends), [audience send](#create-audience-sends), and [debug (test) send](#create-debugtest-sends).
@@ -179,6 +215,19 @@ To create a direct send notification, follow these steps:
179215

180216
1. Send the notification.
181217

218+
You can also use the .NET SDK to create a direct send:
219+
220+
```csharp
221+
var browserSubscriptionEndpoint = "";
222+
var browserPushHeaders = new Dictionary<string, string>
223+
{
224+
{ "P256DH", "" },
225+
{ "Auth", "" },
226+
};
227+
228+
var directSendOutcome = await notificationHubClient.SendDirectNotificationAsync(new BrowserNotification("payload", browserPushHeaders), browserSubscriptionEndpoint);
229+
```
230+
182231
### Create audience sends
183232

184233
For an audience send, use the same `ServiceBus Notification-Format` header used for a direct send, and modify the message payload as desired. Optionally, specify a tag expression using the `ServiceBusNotification-Tags` header. For more information about creating an audience send, see [Send an APNS native notification](/rest/api/notificationhubs/send-apns-native-notification).

0 commit comments

Comments
 (0)