簡體   English   中英

推送通知Windows 8.1

[英]Push Notification for Windows 8.1

我的想法:

  1. 該應用獲取了一個URI。

  2. 該應用程序將URI發送到我的數據庫。

  3. 管理員面板,其中admin發送一條消息,該消息作為通知發送到DB中存在的所有URI。

我發現這個代碼可以將通知發送到我的數據庫中的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軟件包中找到Phone。 我假設它已被Windows 8.1棄用? 我是Windows的新手,我可以與Android的GCM相關,並為Android應用實現相同的功能。

如何獲取Windows手機的URI以將其發送到服務器?

像這樣做:

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

有一個很好的樣本在這里 不要忘記您必須將您的應用程序與商店相關聯,其中包括創建應用程序和注冊WNS服務以獲取客戶機密。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM