Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Notification for Windows 8.1

What I have in my mind:

  1. The app gets a URI.

  2. The app sends the URI to my DB.

  3. An admin panel where admin sends a message which goes as notification to all the URI present in DB.

I have found this code which can send the notification to the URI in my DB.

However I am unable to generate the URI and send it to the server. I have tried using this code

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

        }
    }

But Visual Studio does not recognize HttpNotificationChannel. I have tried adding 'using Microsoft.Phone.Notification' but it doesn't find Phone within Microsoft package. I am assuming that it's deprecated for Windows 8.1? I am new to Windows, I could relate to GCM for Android and implemented the same for the Android app.

How can I get the URI for a Windows phone to send it to the server?

like image 205
Pranjal Avatar asked Dec 14 '25 02:12

Pranjal


1 Answers

Do it like this:

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

There's a good sample here. Don't forget you have to associate your application with store which includes creating app and registering for WNS services to get client secret.

like image 56
norekhov Avatar answered Dec 16 '25 15:12

norekhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!