C# Windows 8.1的推送通知
我的想法是:C# Windows 8.1的推送通知,c#,windows-phone-8.1,C#,Windows Phone 8.1,我的想法是: 该应用程序获得一个URI 应用程序将URI发送到my DB 一个管理面板,其中管理员向数据库中的所有URI发送一条消息作为通知 我已经找到了可以将通知发送到我数据库中的URI的方法 但是,我无法生成URI并将其发送到服务器。 我试过使用这个代码 public MainPage() { /// Holds the push channel that is created or found. HttpNotificationChannel pus
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()));
}
}
public主页()
{
///保存已创建或找到的推送通道。
HttpNotificationChannel推送通道;
//我们推送频道的名称。
字符串channelName=“RawSampleChannel”;
初始化组件();
//试着找到推送通道。
pushChannel=HttpNotificationChannel.Find(channelName);
//如果未找到通道,则创建到推送服务的新连接。
if(pushChannel==null)
{
pushChannel=新的HttpNotificationChannel(通道名称);
//在尝试打开通道之前注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
pushChannel.HttpNotificationReceived+=新事件处理程序(pushChannel\u HttpNotificationReceived);
pushChannel.Open();
}
其他的
{
//频道已经打开,所以只需注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
pushChannel.HttpNotificationReceived+=新事件处理程序(pushChannel\u HttpNotificationReceived);
//出于测试目的显示URI。通常,URI会在此时传递回web服务。
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
Show(String.Format(“通道Uri为{0}”),
pushChannel.ChannelUri.ToString());
}
}
但是Visual Studio无法识别HttpNotificationChannel
。我已尝试添加“使用Microsoft.Phone.Notification”,但在Microsoft软件包中找不到Phone。我假设它不适合Windows 8.1?我是Windows新手,我可以与Android的GCM联系起来,并在Android应用程序中实现同样的功能
如何获取Windows phone的URI以将其发送到服务器?如下操作:
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var uri = channel.Uri
有一个很好的样品。不要忘记,您必须将应用程序与应用商店相关联,其中包括创建应用程序和注册WNS服务以获取客户机密。感谢您在创建客户机密后所做的工作。你能帮助我如何接收原始通知吗?我的代码使用了“HttpNotificationChanel”,但它不起作用。请使用我提供的示例。这里有一个Scenario3_listing.xaml.cs,其中包含侦听部分。这是一个涵盖所有方面的完整客户端应用程序。