1
votes

I have followed all the steps given in the documentation to register for a push notification from the Parse website. (All the steps in the sense I downloaded the default project and added event handler to handle the incoming toast notification).

      ParseClient.Initialize("x0uNa3Q164SVGKbH4mxZJaxWxsuYtslB5tVPj893",
          "cXFv9RQAoray9xFdwdcZCHXrrkrM6KNd0WyN194H");


      this.Startup += async (sender, args) =>
      {
          // This optional line tracks statistics around app opens, including push effectiveness:
          ParseAnalytics.TrackAppOpens(RootFrame);

          // By convention, the empty string is considered a "Broadcast" channel
          // Note that we had to add "async" to the definition to use the await keyword
          await ParsePush.SubscribeAsync("");

      };

      ParsePush.ToastNotificationReceived += ParsePushOnToastNotificationReceived;

and the handler

      private void ParsePushOnToastNotificationReceived(object sender, 
      NotificationEventArgs notificationEventArgs)
  {
      var s = new ShellToast();
      s.Content = notificationEventArgs.Collection.Values.First();
      s.Title = "My Toast";
      s.Show();

  }


      private async void Application_Launching(object sender, LaunchingEventArgs e) 
  {
    await ParseAnalytics.TrackAppOpenedAsync();
  }

When I run the app in the emulator it registers the app and I can verify it in my dashboard. But as soon as I send push notification from the website number of registered devices will be shown as 0 and the app doesnt receive the notification.

One thing to mention is this behavior is not consistent. Sometimes the app does receive the notification. Can anyone mention the reason for this or any other point I am missing?

Number of recipients = 1Number of recipients became 0

2
I am using MVVM pattern. This is the only piece of code which is present in App.xaml.cs I am registering for the event on application start up. - Arjun K R

2 Answers

1
votes

One thing to note is that ShellToast.Show() should only be used from background task. If you call it when an app is in the foreground, toast won't be shown. http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.shell.shelltoast.show(v=vs.105).aspx So, be sure your app is not in the foreground when you expect to see toast notification.

1
votes

Firstly you will be shown toast notification only if the foreground app is not running.
If your app is running when you receive push notification you have to do like:

void ParsePushOnToastNotificationReceived(object sender, 
      NotificationEventArgs notificationEventArgs)
  {
      Deployment.Current.Dispatcher.BeginInvoke(()=>{
          // do anything
          MessageBox.Show("got notification");
      });

  }

If your app is not running the os will handle the notification properly, you dont have to do anything.