2014-12-20 105 views
0

我已經開發了Windows Phone 8應用程序,並且我已經在其中實施了推送通知服務。 當我在Windows Phone Emulator中啓動應用程序時,它會創建URI(從MPNS獲取)並將它發送到數據庫,以便下次發送通知,但是問題是,當我重新啓動模擬器時,URI發生更改,我想保留設備或模擬器使用相同的URI,那我該怎麼做?推送通知爲Windows Phone 8獲取URI

我對生成的URI代碼

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())); 
      string strURI = pushChannel.ChannelUri.ToString(); 
      (App.Current as App).phoneURI = strURI; 
     } 

我拿起這個(App.Current爲APP).phoneURI和發送到數據庫,但是當我重新啓動模擬器它得到改變?

並且有時它給URI和某個拋出異常類型「System.NullReferenceException」發生在TileNotificationClient.DLL的例外,但是在用戶代碼在這條線string strURI = pushChannel.ChannelUri.ToString();

+0

關於你的NullReferenceException:你可以檢查你的頻道是否真的有channelUri?不確定,但如果它沒有完全打開,有時它還沒有uri頻道。 –

回答

0

的(IMHO)沒有處理仿真器的好處在於,每次重新啓動時都有一個清新,乾淨的系統。

Notifikation uri不保證在真實設備上保持一致。你應該在你的應用程序設計中加入變化的渠道Uris。

相關問題