Windows phone 8 Windows Phone 8频道更新未触发
我在开发Windows Phone推送通知时遇到问题。根本没有触发Windows phone 8 Windows Phone 8频道更新未触发,windows-phone-8,push-notification,mpns,Windows Phone 8,Push Notification,Mpns,我在开发Windows Phone推送通知时遇到问题。根本没有触发ChannelUriUpdated事件。当我注册ConnectionStatusChanged事件时,如下所示: void pushChannel_ConnectionStatusChanged(object sender, NotificationChannelConnectionEventArgs e) { var state = e.ConnectionStatus; } 并且,连接状态
ChannelUriUpdated
事件。当我注册ConnectionStatusChanged
事件时,如下所示:
void pushChannel_ConnectionStatusChanged(object sender, NotificationChannelConnectionEventArgs e)
{
var state = e.ConnectionStatus;
}
并且,连接状态更改
会持续触发。“状态”值交替连接和断开
我使用代码:
任何帮助都将不胜感激。请点击下面的链接
使用下面的代码为我工作
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()));
}
}
HttpNotificationChannel推送通道;
//我们推送频道的名称。
字符串channelName=“ToastSampleChannel”;
初始化组件();
//试着找到推送通道。
pushChannel=HttpNotificationChannel.Find(channelName);
//如果未找到通道,则创建到推送服务的新连接。
if(pushChannel==null)
{
pushChannel=新的HttpNotificationChannel(通道名称);
//在尝试打开通道之前注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
//仅当您需要在应用程序运行时接收通知时,才注册此通知。
pushChannel.ShellToastNotificationReceived+=新事件处理程序(pushChannel\u ShellToastNotificationReceived);
pushChannel.Open();
//为toast事件绑定此新频道。
pushChannel.BindToShellToast();
}
其他的
{
//频道已经打开,所以只需注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
//仅当您需要在应用程序运行时接收通知时,才注册此通知。
pushChannel.ShellToastNotificationReceived+=新事件处理程序(pushChannel\u ShellToastNotificationReceived);
//出于测试目的显示URI。通常,URI会在此时传递回web服务。
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
Show(String.Format(“通道Uri为{0}”),
pushChannel.ChannelUri.ToString());
}
}
希望它对您有用…如果这里有任何查询而不是评论…您发布的代码与我使用的MSDN推送通知示例代码相同。