Windows News app uses Notification Hubs
Platform Notification Service App back-end Client app
APNsWNS Notification Hub App back-end iOS app Windows Store app
var hub = new NotificationHub(“ ", " "); var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); await hub.RegisterNativeAsync(channel.Uri);
var hubClient = NotificationHubClient.CreateClientFromConnectionString(" ", “ "); var toast "; hubClient.SendWindowsNativeNotificationAsync(toast);
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken { … SBNotificationHub* hub = [[SBNotificationHub alloc] " [hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) { if (error != nil) { registering for notifications: error); } }]; }
In your main activity: Notification Hub hub = new NotificationHub(" ", " ", context); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); String regid = gcm.register(SENDER_ID); NativeRegistration r = hub.register(regid);
var hubClient = NotificationHubClient.CreateClientFromConnectionString(" ", “ "); var toastForIos "; hubClient.SendAppleNativeNotificationAsync(toastForIos); var toastForAndroid "; 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 } } );
Notification Hub App back-end Tag:”Beatles”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}); }
Service Bus Notification Hub App back-end $(message) { aps: { alert: “$(message)” } { message: “Hello!” } Hello!
Service Bus Notification Hub App back-end $(tempF) { aps: { alert: “$(tempC)” } { tempC: “23”, tempF: “73” } 73 23