我想控制来自WNS服务器的推送通知(toast),然后才能在屏幕上显示..我可以在Android中完成,但我可以在Windows Phone中进行吗?? ??
答案 0 :(得分:1)
你可以在你的情况下使用吐司通知。 Toast通知由OS处理。您可以在OnLaunched事件App中获取启动参数的有效负载。
Server app,您可以将其用于测试。您也可以使用模拟器进行推送测试。
答案 1 :(得分:1)
我相信您需要原始通知,这是您的手机在应用程序运行时处理的通知。
创建推送频道时,您可以使用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
}