简体   繁体   中英

Windows Phone 7 Push Notification

I am developing an application which is Push Notification Enabled. I have a web service which sends me notification. I wrote the following code in order to implement the push notification in my WP7 app.

  1. Created a Uri from the below code

      channel = new HttpNotificationChannel("Diary"); channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived; channel.ChannelUriUpdated += channel_ChannelUriUpdated; channel.ErrorOccurred += channel_ErrorOccurred; channel.Open(); channel.BindToShellToast(); channel.BindToShellTile(); 

By calling the above method i got an uri http://dm2.notify.live.net/throttledthirdparty/01.00/AQHhBKglq-YiSoltOFnZwEWxAgAAAAADBwAAAAQUZm52OkJCMjg1QTg1QkZDMkUxREQFBlVTU0MwMQ

This is the Uri i should give to my web service team.

But each time when i open my application my channel uri is getting changed. Why this is dynamic?. Please make me direct whether am i going in right direction or should i register somewhere my application to get the uri?

If your app is in foreground and you send the notification then, only channel_ShellToastNotificationReceived event is fired. If your app is not running in the foreground then this event is not fired, instead of this app navigates to the page(if you have provided that) which you have mentioned in the payload of the notification "<wp:Param>/Home.xaml</wp:Param>" (Home.xaml here).

If in case you have not passed any thing in the <wp:Param> then the code written below runs:

 // 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);
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

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

This code must be in the else part of the code which you have written. We can help further if you provide some more code like payload and code written for receiving notifications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM