Push Notification for Windows 8.1
What I mean:
-
The application receives the URI.
-
The app is sending the URI to my DB.
-
Admin panel, where the administrator sends a message that is sent as notification of all URIs present in the database.
I found this code that can send a notification to a URI in my DB.
However, I am unable to generate the URI and send it to the server. I 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 doesn't recognize HttpNotificationChannel
. I tried adding "using Microsoft.Phone.Notification" but it doesn't find "Phone in Microsoft package". I am assuming it is outdated for Windows 8.1? I'm new to Windows, I could refer to GCM for Android and have implemented the same for an Android app.
How can I get the URI for a Windows phone to send to the server?
source to share
Do it like this:
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var uri = channel.Uri
Here's a good example here . Don't forget that you need to link your app to the store, which involves creating an app and registering WNS services to get client privacy.
source to share