Windows News app uses Notification Hubs Client app Platform Notification Service App back-end iOS app Windows Store app App back-end APNs Notification Hub WNS.

Download Report

Transcript Windows News app uses Notification Hubs Client app Platform Notification Service App back-end iOS app Windows Store app App back-end APNs Notification Hub WNS.

Windows News app uses
Notification Hubs
Client app
Platform
Notification
Service
App back-end
iOS app
Windows Store
app
App back-end
APNs
Notification Hub
WNS
var hub = new NotificationHub(“<hub name>", "<connection string>");
var channel = await
PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
await hub.RegisterNativeAsync(channel.Uri);
var hubClient =
NotificationHubClient.CreateClientFromConnectionString("<connection string>",
“<hub name>");
var toast = @“<notification payload>";
hubClient.SendWindowsNativeNotificationAsync(toast);
(void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {
…
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:
@"<connection string>" notificationHubPath:@"mynh"];
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error registering for notifications: %@", error);
}
}];
}
In your main activity:
Notification Hub hub = new NotificationHub("<hub name>", "<connection string>",
context);
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regid = gcm.register(SENDER_ID);
NativeRegistration r = hub.register(regid);
var hubClient =
NotificationHubClient.CreateClientFromConnectionString("<connection string>",
“<hub name>");
var toastForIos = @“<notification payload>";
hubClient.SendAppleNativeNotificationAsync(toastForIos);
var toastForAndroid = @“<notification payload>";
hubClient.SendGcmNativeNotificationAsync(toastForAndroid);
var azure = require('azure');
var notificationHubService = azure.createNotificationHubService('hubname',
'connectionString');
notificationHubService.wns.sendToastText01(null,
{
text1: 'Hello from Node and Mobile Services!'
},
function (error)
{
if (!error) { // message sent successfully }
}
);
No need to store and maintain ChannelURIs.
Device registrations expire.
App back-end
Tag:”Beatles”
Notification Hub
Tag:”Wailers”
Tag:”Beatles”
Notification Hub
App back-end
// POST api/register
public async void Post(bool instId, bool channelUri, bool userId) {
// We assume a windows store app (if coding a multiplatform app, a ‘platform‘ parameter should be passed)
…
if (!authorizedToRegisterTag(userId))
{ throw new Exception("User not authorized to register"); }
var regsForInstId = await hubClient.GetRegistrationsByTag(instId, 100);
bool updated = false;
bool firstRegistration = true;
foreach (var registrationDescription in regsForInstId) {
if (firstRegistration) {
var winReg = registrationDescription as WindowsRegistrationDescription;
winReg.ChannelUri = new Uri(channelUri);
winReg.Tags.Clear();
winReg.Tags.UnionWith(new string[] {instId, userId});
hubClient.UpdateRegistration(winReg);
updated = true;
firstRegistration = false;
} else {
// if templates are not used, delete all extra registrations with this installation id.
hubClient.DeleteRegistration(registrationDescription);
}
}
// if not updated, a new registration has to be created for the device
if (!updated) {
hubClient.CreateWindowsNativeRegistration(channelUri, new string[] {instId, userId});
}
}
<toast>
<visual>
<binding template=\"ToastText01\">
<text id=\"1\">$(message)</text>
</binding>
</visual>
</toast>
Hello!
{ message: “Hello!” }
App back-end
Service Bus
Notification Hub
Hello!
{
aps: {
alert: “$(message)”
}
}
<toast>
<visual>
<binding template=\"ToastText01\">
<text id=\"1\">$(tempF)</text>
</binding>
</visual>
</toast>
73
{tempC: “23”, tempF: “73”}
App back-end
Service Bus
Notification Hub
23
{
aps: {
alert: “$(tempC)”
}
}
Notification Hubs Guidance
tutorial feature guide
tutorial feature guide
tutorial feature guide
.NET Server SDK
Node Server SDK
Windows Store Device SDK
iOS Device SDK
Android Device SDK