i am facing a weird problem. I am using Windows phone 8.1 silverlight and Windows universal link for toast notification. I am able to get the toast notification in Windows Phone app it is nearly same way in Windows 8.1 as mentioned in the link. But toasts are not comming in Windows 8.1 part.
Steps :-
1 -> I have enabled the Toast from Package.appxmanifest
file.
2 -> Then i have added this code in App.Xaml.cs in on_launched event as mentioned
It is showing the registeration successful as mentioned in the link
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
var result = await hub.RegisterNativeAsync(channel.Uri);
// 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();
}
}
3 -> Now i send the notification from back end(Hub is working in case of phone mpns notification).
public static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
await hub.SendWindowsNativeNotificationAsync(toast);
}
Question : - Do you guys have a clue why it is not working in Windows 8.1 or what i am missing. This is the simplest example i am going through. Any help is appreciated.
Edit :- This is something interesting.
When i tried to send the notification from azure portal. From DEBUG
tab of My-NotificationHub
and from here i choose WNS toast then it showing an error.
Error
- The token obtained from the token provider is wrong
but when i tried to send MPNS
notification then there is no error. as i already mentioned it is working for WP 8.1 silverlight MPNS toast
.
What could be the cause of this error ?
Instantiate a Toast objectUse the makeText() method, which takes the following parameters: The application Context . The text that should appear to the user. The duration that the toast should remain on the screen.
Start screen application shortcuts are in the %AppData%\Microsoft\Windows\Start Menu\Programs folder, and you need to add a shortcut to this folder to show toast notifications.
A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app. This quickstart walks you through the steps to create, deliver, and display a Windows 10 or Windows 11 toast notification using rich content and interactive actions.
Access the Charm Bar on the right side of the screen or Windows Key + C on your keyboard and click on settings, as in. After clicking on Settings, you will click on More PC Settings that shows up in the end, as in. In this step, you will see the PC settings. You click on Notification Option in the left pane, as in.
Toast will not work on simulator, as stated in the MSDN documentation:
Note When testing toast notification code functionality through Microsoft Visual Studio, you must use either the Local Machine or Remote Machine debug setting on a Windows x86, x64, or Windows Runtime machine. You cannot use the Visual Studio Simulator debug function option—your code will compile and run in the Simulator, but the toast will not appear.
Source: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With