gpt4 book ai didi

c# - Windows Phone silverlight 8.1 Http NotificationChannel ChannelUri 更新未被击中

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

我有一个非常基本的 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 in my Package.appmanifest....我错过了什么运动鞋?

最佳答案

我试过下面的通知代码:

HttpNotificationChannel pushChannel;

将 pushChannel 作为 globle 放入它在 EventHandler 中使用的 App.xaml.cs 文件中

string channelName = "PushChannel";
pushChannel = HttpNotificationChannel.Find(channelName);
//Push Notifications
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.enter code here
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//pushURI = pushChannel.ChannelUri.ToString();
//MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
Notification.ChannelURI = pushChannel.ChannelUri.ToString();
});
}

将以上代码放入 App() 中的 App.xaml.cs 文件中

事件:

void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e1)
{
try
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(String.Format("Channel Uri is {0}", e1.ChannelUri.ToString()));
});
}
catch (Exception ex)
{ }
}
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e2)
{
try
{
// Error handling logic for your particular application would be here.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e2.ErrorType, e2.Message, e2.ErrorCode, e2.ErrorAdditionalData));
});
}
catch (Exception ex)
{ }
}

关于c# - Windows Phone silverlight 8.1 Http NotificationChannel ChannelUri 更新未被击中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31847796/

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