2013-10-11 56 views
1

我在開發Windows Phone推送通知時遇到問題。 ChannelUriUpdated事件根本沒有被觸發。當我註冊ConnectionStatusChanged事件如下:Windows Phone 8 ChannelUriUpdated未解僱

void pushChannel_ConnectionStatusChanged(object sender, NotificationChannelConnectionEventArgs e) 
    { 
     var state = e.ConnectionStatus; 
    } 

而且ConnectionStatusChanged不斷觸發。 「狀態」值交替連接和斷開。

我使用代碼: MSDN Push Notification Sample Code

任何幫助將不勝感激。

回答

0

Follw以下鏈接

How to send and receive toast notifications for Windows Phone

Push Notification for windows phone

下面的代碼使用它爲我的工作

HttpNotificationChannel pushChannel; 

      // The name of our push channel. 
      string channelName = "ToastSampleChannel"; 

      InitializeComponent(); 

      // Try to find the push channel. 
      pushChannel = HttpNotificationChannel.Find(channelName); 

      // If the channel was not found, then create a new connection to the push service. 
      if (pushChannel == null) 
      { 
       pushChannel = new HttpNotificationChannel(channelName); 

       // Register for all the events before attempting to open the channel. 
       pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
       pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 

       // Register for this notification only if you need to receive the notifications while your application is running. 
       pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); 

       pushChannel.Open(); 

       // Bind this new channel for toast events. 
       pushChannel.BindToShellToast(); 

      } 
      else 
      { 
       // The channel was already open, so just register for all the events. 
       pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
       pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 

       // Register for this notification only if you need to receive the notifications while your application is running. 
       pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); 

       // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. 
       System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); 
       MessageBox.Show(String.Format("Channel Uri is {0}", 
        pushChannel.ChannelUri.ToString())); 

      } 
     } 

希望它會爲你工作......如果不是任何評論這裏查詢...

+0

您發佈的代碼是一樣的機智h我使用MSDN推送通知示例代碼。 – Joel