控制推送通知
本文关键字:通知 控制 | 更新日期: 2023-09-27 18:33:59
我想在WNS服务器显示在屏幕上之前控制来自WNS服务器的推送通知(toast)。我可以在Android中做到这一点,但我可以在Windows Phone中做到这一点吗?
您可以在
您的情况下使用 Toast 通知。Toast 通知由操作系统处理。 您可以在应用程序的启动事件中获取启动参数中的有效负载。
客户端示例
服务器应用程序,您可以使用它进行测试。还可以使用模拟器进行推送测试。
我相信
您想要原始通知,这是您的手机在应用程序运行时处理的通知。
创建推送通道时,可以使用 OnPushNotificationRecieved 事件在接收通知时执行逻辑。
这样,如果应用程序正在运行,您的逻辑将在通知出现在屏幕上之前触发。
如果应用程序未运行,它将是常规的 Toast。
例:
_channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
_channel.PushNotificationReceived += OnPushNotificationReceived;
private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
{
switch (args.NotificationType)
{
case PushNotificationType.Badge:
this.OnBadgeNotificationReceived(args.BadgeNotification.Content.GetXml());
break;
case PushNotificationType.Tile:
this.OnTileNotificationReceived(args.TileNotification.Content.GetXml());
break;
case PushNotificationType.Toast:
this.OnToastNotificationReceived(args.ToastNotification.Content.GetXml());
break;
case PushNotificationType.Raw:
this.OnRawNotificationReceived(args.RawNotification.Content);
break;
}
args.Cancel = true;
}
private void OnBadgeNotificationReceived(string notificationContent)
{
// Code when a badge notification is received when app is running
}
private void OnTileNotificationReceived(string notificationContent)
{
// Code when a tile notification is received when app is running
}
private void OnToastNotificationReceived(string notificationContent)
{
// Code when a toast notification is received when app is running
// Show a toast notification programatically
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(notificationContent);
var toastNotification = new ToastNotification(xmlDocument);
//toastNotification.SuppressPopup = true;
ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
}
private void OnRawNotificationReceived(string notificationContent)
{
// Code when a raw notification is received when app is running
}