Reputation: 27
What I have in my mind:
The app gets a URI.
The app sends the URI to my DB.
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?
Upvotes: 3
Views: 1261
Reputation: 4318
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.
Upvotes: 2