【发布时间】:2015-08-06 05:54:19
【问题描述】:
我有一个非常基本的 Windows Phone Silverlight 8.1 应用程序,其中包含以下内容(我想在将其添加到更大的现有应用程序之前证明这个概念):
HttpNotificationChannel pushChannel;
void registerPushChannel()
{
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);
// code which passes the new channel URI back to my web service
}
}
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
});
}
问题是 PushChannel_ChannelUriUpdated 永远不会被击中,我就是不知道为什么!
我已经在我的 WMAppManifest.xml 中设置了 ID_CAP_PUSH_NOTIFICATION 并且还 Toast Capable = yes 在我的 Package.appmanifest 中......我错过了什么运动鞋?
【问题讨论】:
-
哪里有问题?
-
pushChannel.Uri 在 pushChannel.Open() 之后总是为空;并且连接状态已断开。然后当我调用 NotificationHub hub = new NotificationHub(hubName, connectionString);等待 hub.RegisterNativeAsync(pushChannel.ChannelUri.ToString());它在 RegisterNativeAsync 上引发 NullReferenceException
-
您尝试过我发布的答案吗?
标签: c# silverlight push-notification windows-phone-8.1