gpt4 book ai didi

c# - 适用于 Windows 8.1 的推送通知

转载 作者:行者123 更新时间:2023-11-30 16:53:43 25 4
gpt4 key购买 nike

我的想法是:

  1. 应用获取 URI。

  2. 应用将 URI 发送到我的数据库。

  3. 一个管理面板,管理员可以在其中发送一条消息,该消息作为通知发送给数据库中存在的所有 URI。

我找到了这个 code它可以将通知发送到我的数据库中的 URI。

但是我无法生成 URI 并将其发送到服务器。我试过使用这段代码

public MainPage()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;

// The name of our push channel.
string channelName = "RawSampleChannel";

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);
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);

// 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()));

}
}

但 Visual Studio 无法识别 HttpNotificationChannel。我试过添加“使用 Microsoft.Phone.Notification”,但在 Microsoft 包中找不到电话。我假设 Windows 8.1 已弃用它?我是 Windows 的新手,我可以了解适用于 Android 的 GCM 并为 Android 应用实现相同的功能。

如何获取 Windows 手机的 URI 以将其发送到服务器?

最佳答案

这样做:

var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var uri = channel.Uri

有一个很好的样本here .不要忘记您必须将您的应用程序与商店相关联,这包括创建应用程序和注册 WNS 服务以获取客户端密码。

关于c# - 适用于 Windows 8.1 的推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31131630/

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