推送通知Windows 8.1

时间:2015-06-30 07:00:41

标签: c# windows-phone-8.1

我的想法是:

  1. 该应用获取了一个URI。

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

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

  4. 我找到了这个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&#39;添加&#39;但它并没有在Microsoft软件包中找到Phone。我假设它已被Windows 8.1弃用了?我是Windows的新手,我可以与Android的GCM相关,并为Android应用程序实现相同的功能。

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

1 个答案:

答案 0 :(得分:2)

这样做:

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

有一个很好的样本here。不要忘记你必须将你的应用程序与商店联系起来,包括创建应用程序和注册WNS服务以获取客户机密。