0

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?

Eran
  • 387,369
  • 54
  • 702
  • 768
Shafiq Abbas
  • 484
  • 1
  • 5
  • 18
  • Are you debugging the emulator or your original device when you try to get that url? – pazcal Nov 18 '13 at 07:14
  • I tried in my WP7 device.. – Shafiq Abbas Nov 18 '13 at 07:41
  • I found it. I always closed the channel when i start application and so it is creating a new channel uri. But i have my second problem. I gave the uri to the web service. they sent the notification. But the channel_ShellToastNotificationReceived is not firing. – Shafiq Abbas Nov 18 '13 at 08:04
  • Do you have some extra code to share, like the XML template and the class where the ShellToastNotificationReceived is defined in? – pazcal Nov 18 '13 at 11:21
  • It won't fire if your app is in background. – Swapnika Nov 19 '13 at 04:46

1 Answers1

1

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.

Nitika
  • 103
  • 11