我知道这已被多次提出,但找不到答案。
我正在尝试使用以下代码在我的应用程序中设置推送通知,但是我遇到了频道 uri null 问题。
我已经在 4 个不同的设备 + 模拟器上尝试了该应用程序,所有设备都在相同的网络条件下(工作 WiFi - 家庭 WiFi - 3G),其中 2 个设备是 Lumia 920,两者都无法获得通道 uri,而其他 2 个设备是 HTC 8X 和Lumia 820可以成功获取频道uri并注册推送。
模拟器也可以成功获取通道uri。
在其中一个 Lumia 920 上,它设法获得了一个频道 uri,但我再次卸载并安装了该应用程序,从那时起就无法获得任何频道 uri。
以下是我的场景:
1- 安装在 3G 上的 Lumia 920 Black 工作正常,卸载/重新安装停止在任何连接上工作(3G - 工作 WiFi - 家庭 WiFi) 2- 安装在 3G 上的 Lumia 920 Yellow - 工作 WiFi - 家庭 WIfi 从未设法获得频道 uri 3 - HTC 8X on 3G - 工作 WiFi - 家庭 WiFi 在所有 3 个网络上都运行良好 4- Lumia 820 与 HTC 8X 运行良好
请注意,其他应用程序上的推送通知在所有 4 台设备上都可以正常工作。
对于频道 null uri 的任何反馈/建议,我将不胜感激
下面是我使用的代码,和 MSDN 提供的代码是一样的
public MainPage()
{
/// Holds the push channel that is created or found.
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()));
}
}