About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
windows_first
⚠️
missing_linux_example
⚠️
windows_tools
Summary:
The documentation page demonstrates a Windows bias by providing only Windows-centric code examples and patterns. All sample code is written in C# and uses Windows-specific APIs (such as PushNotificationChannelManager and ApplicationData), with no equivalent Linux, Android, or iOS code samples. The documentation discusses secondary tiles and headers specifically for Windows Store apps, and does not mention or demonstrate how to perform similar registration management from non-Windows platforms or with cross-platform tools. There are no Linux command-line, REST/cURL, or non-Windows SDK examples provided.
Recommendations:
- Add code samples for Linux, Android, and iOS platforms, using their respective notification APIs and SDKs.
- Provide REST API examples using cURL or HTTP libraries in languages common on Linux (e.g., Python, Node.js) to demonstrate cross-platform registration management.
- Include equivalent instructions and code snippets for managing device registration from non-Windows backends (e.g., running on Linux servers).
- Document any platform-specific differences or requirements for registration, and ensure that Windows-specific features (like secondary tiles) are clearly marked as such, with alternatives or notes for other platforms.
- Reorganize sections so that platform-agnostic or cross-platform approaches are presented before or alongside Windows-specific guidance.
Create pull request
Flagged Code Snippets
// Example installation format to show some supported properties
{
installationId: "",
expirationTime: "",
tags: [],
platform: "",
pushChannel: "",
………
templates: {
"templateName1" : {
body: "",
tags: [] },
"templateName2" : {
body: "",
// Headers are for Windows Store only
headers: {
"X-WNS-Type": "wns/tile" }
tags: [] }
},
secondaryTiles: {
"tileId1": {
pushChannel: "",
tags: [],
templates: {
"otherTemplate": {
bodyTemplate: "",
headers: {
... }
tags: [] }
}
}
}
}
// Initialize the notification hub
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(listenConnString, hubName);
// The Device ID from the PNS
var pushChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
// If you are registering from the client itself, then store this registration ID in device
// storage. Then when the app starts, you can check if a registration ID already exists or not before
// creating.
var settings = ApplicationData.Current.LocalSettings.Values;
// If we didn't store a registration ID in application data, store in application data.
if (!settings.ContainsKey("__NHRegistrationId"))
{
// Make sure there are no existing registrations for this push handle (used for iOS and Android)
string newRegistrationId = null;
var registrations = await hub.GetRegistrationsByChannelAsync(pushChannel.Uri, 100);
foreach (RegistrationDescription registration in registrations)
{
if (newRegistrationId == null)
{
newRegistrationId = registration.RegistrationId;
}
else
{
await hub.DeleteRegistrationAsync(registration);
}
}
newRegistrationId = await hub.CreateRegistrationIdAsync();
settings.Add("__NHRegistrationId", newRegistrationId);
}
string regId = (string)settings["__NHRegistrationId"];
RegistrationDescription registration = new WindowsRegistrationDescription(pushChannel.Uri);
registration.RegistrationId = regId;
registration.Tags = new HashSet<string>(YourTags);
try
{
await hub.CreateOrUpdateRegistrationAsync(registration);
}
catch (Microsoft.WindowsAzure.Messaging.RegistrationGoneException e)
{
settings.Remove("__NHRegistrationId");
}
var hub = NotificationHubClient.CreateClientFromConnectionString("{connectionString}", "hubName");
// create a registration description object of the correct type, e.g.
var reg = new WindowsRegistrationDescription(channelUri, tags);
// Create
await hub.CreateRegistrationAsync(reg);
// Get by ID
var r = await hub.GetRegistrationAsync<RegistrationDescription>("id");
// update
r.Tags.Add("myTag");
// update on hub
await hub.UpdateRegistrationAsync(r);
// delete
await hub.DeleteRegistrationAsync(r);