我有 WNS 服务的 uwp app toast 通知。我的应用程序在 Visual Studio 中吃午饭时工作正常,但是当我从 appx 文件夹运行应用程序时,没有显示 toast 通知。吐司通知时我没有任何例外。请原谅我的语言不好。
private async void ToastNotification(NotificationModel notificationModel)
{
string title = notificationModel.Title;
string content = notificationModel.Content;
string image = notificationModel.ImageUrl;
int conversationId = notificationModel.Id;
ToastContent toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
new AdaptiveImage()
{
Source = await DownloadImageToDisk(image)
}
},
AppLogoOverride = new ToastGenericAppLogo()
{
Source = await DownloadImageToDisk(notificationModel.IconUrl),
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
},
Actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("view", new QueryString()
{
{ "action", "GoToLink" },
{ "link", notificationModel.LinkAddress }
}.ToString())
}
},
ActivationType = ToastActivationType.Background,
Scenario = ToastScenario.Reminder
};
var doc = new XmlDocument();
doc.LoadXml(toastContent.GetContent());
var toast = new ToastNotification(doc);
toast.Failed += (o, args) =>
{
var message = args.ErrorCode;
MessageBox.Show(message.Message);
};
DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
_beharaSqlDependency.NotificationIsSent(notificationModel.Id);
}