首页 文章

如何在Windows Phone中设置推送通知接收消息目标页面?

提问于
浏览
1

我需要在windows phone中设置推送通知接收消息目标页面 . 我可以发送和接收吐司推送通知,但是当我点击收到的吐司消息时,它会转到主页面 . 当我点击Toast消息时,我需要在目标页面中打开该应用程序 . 请告诉我为什么我在这个问题上面临问题以及我的代码中出了什么问题 .

我的代码如下:

C#接收目标页面:

void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
    {
        StringBuilder message = new StringBuilder();
        string relativeUri = string.Empty;

        message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

        // Parse out the information that was part of the message.
        foreach (string key in e.Collection.Keys)
        {
            message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

            if (string.Compare(
                key,
                "wp:Param",
                System.Globalization.CultureInfo.InvariantCulture,
                System.Globalization.CompareOptions.IgnoreCase) == 0)
            {
                relativeUri = e.Collection[key];

            }
        }

        // Display a dialog of all the fields in the toast.
        Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString()));

    }
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        //  If we navigated to this page
        // from the MainPage, the DefaultTitle parameter will be "FromMain".  If we navigated here
        // when the secondary Tile was tapped, the parameter will be "FromTile".
        textBlockFrom.Text = "Navigated here from " + this.NavigationContext.QueryString["NavigatedFrom"];

    }

我使用PHP代码发送推送通知:

<?php 
  final class WindowsPhonePushDelay
  {

   const Immediate=0;

   private function __construct(){}
 }

 class WindowsPhonePushNotification
 {
  private $notif_url = '';

  function WindowsPhonePushNotification($notif_url)
  {
     $this->notif_url = $notif_url;
  }
  public function push($target,$message,$notif_url)
  {

   // Create the toast message
   $toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
            "<wp:Notification xmlns:wp=\"WPNotification\">" .
               "<wp:Toast>" .
                    "<wp:Text1>" . "SendToast" . "</wp:Text1>" .
                    "<wp:Text2>" . $message . "</wp:Text2>" .
                    "<wp:Param>/Receive.xaml?NavigatedFrom=Toast Notification</wp:Param>" .
                    "</wp:Toast> " .
            "</wp:Notification>";

  // Create request to send
     $r = curl_init();
     curl_setopt($r, CURLOPT_URL,$notif_url);
     curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($r, CURLOPT_POST, true);
     curl_setopt($r, CURLOPT_HEADER, true); 

  // add headers
     $httpHeaders=array('Content-type: text/xml; charset=utf-8', 'X-WindowsPhone-Target: toast',
                'Accept: application/*', 'X-NotificationClass: 2','Content-Length:'.strlen($toastMessage));
  curl_setopt($r, CURLOPT_HTTPHEADER, $httpHeaders);

  // add message
  curl_setopt($r, CURLOPT_POSTFIELDS, $toastMessage);

  // execute request
  $output = curl_exec($r);
  curl_close($r);

   }
}

?>

我需要输出,如下图所示

enter image description here

1 回答

  • 0

    作为toast通知的有效载荷的一部分的wp:param应该是uri . 因此它也应该编码为一个 . 在您提供有效负载中有空间的示例中,可能会导致问题 . 你能尝试这样格式吗?

    "<wp:Param>/Receive.xaml?NavigatedFrom=Toast%20Notification</wp:Param>" .
    

    还要确保Receive.xaml确实位于包的根目录中 .

相关问题