我正在尝试在Windows Phone上实现基于推送通知的应用。我已经能够在模拟器上检索Channel Uri,并通过我的服务器向模拟器发送推送通知。
另一方面,我遇到了在我的设备上部署相同解决方案的问题。 Uri的用法返回NullReferenceException。虽然Channel Uri显示“无法评估表达”。
这是我的代码放在页面构造函数中。 我也尝试过更改_pushChannelName。
private static string _pushChannelName = "TestApp";
// Constructor
public MainPage()
{
HttpNotificationChannel pushChannel;
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(_pushChannelName);
if (pushChannel == null)
{
MessageBox.Show("NULL");
pushChannel = new HttpNotificationChannel(_pushChannelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived +=new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
pushChannel.Open();
pushChannel.BindToShellToast();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
//System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
textBox1.Text = pushChannel.ChannelUri.ToString();
}
MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
}
我也尝试过从ChangeUri事件中查看Uri。该事件不会在设备上触发,而Push应用程序正常运行。甚至不符合频道限制。
private void pushChannel_ChannelUriUpdated(Object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
});
}
答案 0 :(得分:1)
许多用户都面临着这个问题。解决方案有两个。
第一种解决方案是停止与市场帐户关联的所有应用程序,游戏和其他软件,并删除或停止通知。重启手机(关机/开机)并等待24小时。
第二个解决方案是向Marketplace付费并注册您的应用程序,从Marketplace获取证书并插入您的应用程序。然后当打开新通道时必须使用静态类“HttpNotificationChannel”的第二个重载构造函数:
[SecuritySafeCritical] public HttpNotificationChannel(string channelName,string serviceName);