同时发送图块和吐司通知吗? [英] sending a tile and toast notification through at the same time?

查看:76
本文介绍了同时发送图块和吐司通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过MSDN教程创建的桌面应用程序(我找不到链接,否则我会链接它).它的作用是,您可以输入连接到Windows Phone仿真器所需的频道URL,并通过应用程序可以发送实时磁贴更新::这是仿真器(侦听器)和发送以下内容的服务的代码数据. :

i have this desktop application that i created through a MSDN tutorial (i cant find the link, otherwise i would have linked it). what it does , it lets you put in the channel URL needed to connect to the WIndows Phone Emulator, and through the application you can send live tile updates, : here is the code for both the emulator (listener), and the service sending the data. :

MainApp-乳化剂:

MainApp - Emultor :

public MainPage()
    {

        HttpNotificationChannel pushChannel;
        string channelName = "TileSampleChannel";
        InitializeComponent();

        pushChannel = HttpNotificationChannel.Find(channelName);

        if (pushChannel == null)
        {
            pushChannel = new HttpNotificationChannel(channelName);

            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            pushChannel.Open();
            pushChannel.BindToShellTile();


        }
        else
        {
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            MessageBox.Show(String.Format("Channel Uri is {0}",
                pushChannel.ChannelUri.ToString()));

        }
    }


    void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {

        Dispatcher.BeginInvoke(() =>
        {
            System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());

            //MessageBox.Show(String.Format("Channel Uri is {0}",
            //    e.ChannelUri.ToString()));

        });
    }

    void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
            MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
                e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
                );
    }

}


这是服务:



here is service :


protected void ButtonSendTile_Click(object sender, EventArgs e)
    {


        try
        {
            string NotifyURI = TextBoxUri.Text.ToString();


            HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(NotifyURI);

            sendNotificationRequest.Method = "POST";


            //Create the toast message

            string notificationData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\">" +
            "<wp:Toast>" +
            "<wp:Text1>WP8 TOAST</wp:Text1>" +
            "<wp:Text2>" + TextBoxBackContent.Text + "</wp:Text2>" +
            "</wp:Toast>" +
            "</wp:Notification>";

            // Create the tile message.
            string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\">" +
                "<wp:Tile>" +
                  "<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
                  "<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
                  "<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
                  "<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
                  "<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
                  "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
               "</wp:Tile> " +
            "</wp:Notification>";

            byte[] notificationMessage = Encoding.Default.GetBytes(tileMessage);


            sendNotificationRequest.ContentLength = notificationMessage.Length;
            sendNotificationRequest.ContentType = "text/xml";
            sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
            sendNotificationRequest.Headers.Add("X-NotificationClass", "1");


            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(notificationMessage, 0, notificationMessage.Length);
            }


            HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
            string notificationStatus = response.Headers["X-NotificationStatus"];
            string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
            string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];


            TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
        }
        catch (Exception ex)
        {
            TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
        }

    }

现在您可以看到有一部分代码写着"//创建吐司消息",

now as you can see there is a part of code that says "//Create the toast message",

如何获得与切片更新一起发送的吐司?这样,当举杯消息通过时,图块也会使用我在页面中键入的相同信息进行更新.

how do i get that toast to be sent with the tile update? so that when the toast message gets through, the tile updates aswell with the same info i types in the page.

目前只有磁贴被更新.

at the moment only the tile gets updated.

这也是主页的图片.

很长的帖子我很抱歉,但是我想提供尽可能多的信息.

im very sorry about the long post , but i want to give as much info as possible.

使用-Visual Studio 2012/Windows Phone 8/C#/Silverlight

using - Visual Studio 2012/Windows Phone 8/C#/Silverlight

谢谢.

推荐答案

将您的xml有效负载合并为一个

Combine your xml payloads into one

string notificationData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Toast>" +
        "<wp:Text1>WP8 TOAST</wp:Text1>" +
        "<wp:Text2>" + TextBoxBackContent.Text + "</wp:Text2>" +
        "</wp:Toast>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
            "<wp:Tile>" +
              "<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
              "<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
              "<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
              "<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
              "<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
              "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
           "</wp:Tile> " +
        "</wp:Notification>";

打开应用程序时,您不会看到吐司通知.收听 PushNotificationReceived 事件,以在您的应用程序运行时拦截推送通知.

You won't see a toast notification when your application is open. Listen for the PushNotificationReceived event to intercept push notifications when your application is running.

这篇关于同时发送图块和吐司通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆