gpt4 book ai didi

c# - pushChannel 在 Windows Phone 8.1 设备中始终为空(推送通知)

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:40 25 4
gpt4 key购买 nike

pushChannel = HttpNotificationChannel.Find(channelName);

但每次我运行应用程序时它都会返回 null

它在 Windows Phone 8.1 设备中给出 null 仅在 wp8 中它正在注册 channel 。

最佳答案

如果它返回推送 channel 为“null”,那么您是否尝试创建推送 channel ?

// 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); <---- Create a channel if it doesn't exist
######################################################################
// 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()));

}

关于c# - pushChannel 在 Windows Phone 8.1 设备中始终为空(推送通知),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com