Windows phone 8 WP8上的推送通知始终生成新URI
我正在开发一个使用原始通知的WindowsPhone8应用程序。对于这一点,我遵循样本 我的代码与示例完全相同:Windows phone 8 WP8上的推送通知始终生成新URI,windows-phone-8,push-notification,Windows Phone 8,Push Notification,我正在开发一个使用原始通知的WindowsPhone8应用程序。对于这一点,我遵循样本 我的代码与示例完全相同: public MainPage() { /// Holds the push channel that is created or found. HttpNotificationChannel pushChannel; // The name of our push channel.
public MainPage()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "RawSampleChannel";
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);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
pushChannel.Open();
}
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);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
// 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()));
}
}
在设备中运行代码后,我发现每次启动应用程序时,它都会生成不同的URI
我意识到HttpNotificationChannel.FindchannelName总是返回null,这就是应用程序总是生成新URI的原因
我已经读过了,但仍然没有帮到我
所以,我的问题是:
如果应用程序已经生成了频道,HttpNotificationChannel.FindChannel Name不应该返回与“null”不同的内容吗?
如果我错过了一些可以帮助我的东西,请告诉我。我浏览了你的帖子和提到的链接。channelUri更新似乎是非常随机的,通常它肯定会因应用程序卸载/安装而更改,但可能还有其他情况。确保用户正确定位的一个可靠方法是将channelUri与另一个唯一标识符关联。例如,在获取channelUri后,您可能希望使用uri和唯一的用户id更新服务器数据库。对于subsequest调用,只能为同一用户更新频道。希望这有点帮助