private async void btnRegisterForNotificationsWithTemplate_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub(_nothubName, _endPoint); var res = await hub.RegisterTemplateAsync(channel.Uri, txtTemplate.Text, "template1"); if (res.RegistrationId != null) { var dlg = new MessageDialog("Success: " + res.RegistrationId); await dlg.ShowAsync(); } }
public async void RegisterNotificationHubs(string channel) { var connectionString = ConnectionString.CreateUsingSharedAccessKey( MobileServiceConfig.NotificationHubUri, MobileServiceConfig.NotificationHubKey, MobileServiceConfig.NotificationHubSecret); NotificationHub notificationHub = new NotificationHub( MobileServiceConfig.NotificationHubName, connectionString); await notificationHub.UnregisterAllAsync(channel); await notificationHub.RegisterTemplateAsync(channel, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>" + "SlapChat" + "</wp:Text1>" + "<wp:Text2>" + "$(msg)" + "</wp:Text2>" + "</wp:Toast> " + "</wp:Notification>", "toast"); }
private async void registerButton_Click(object sender, RoutedEventArgs e) { // Get the current push notification channel var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("myhub", "Endpoint=sb://sabbour.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=GgJk6ED18JfKc4Ch3dmAtoXcmbZXxUdl4fzefq5XyLU="); // Get the selected cityname var cityName = citiesCombobox.SelectedValue as string; // Construct the template the app is expecting var temperatureProperty = celsiusSwitch.IsOn ? "tempC" : "tempF"; var temperatureString = celsiusSwitch.IsOn ? "Celsius" : "Fahrenheit"; var message = "Temperature in " + cityName + " is $(" + temperatureProperty + ") " + temperatureString; // Append the message into the toast template string toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + message + "</text></binding></visual></toast>"; // Register with the notification hub, and pass the cityname as a tag you are interested in as well as the template await hub.RegisterTemplateAsync(channel.Uri, toastTemplate, "TemperatureToastTemplate", new string[] { cityName }); }
private async void btnTemplates_Click(object sender, RoutedEventArgs e) { var hub = new NotificationHub("HubName", "ListenConnectionString"); var template = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>"; var result = await hub.RegisterTemplateAsync(App.ChannelUri, template, "message"); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }