windows-phone-8parse-platformpush-notificationmpns

Windows Phone app not receiving push notification from Parse.com


I have followed this tutorial on setting up Parse push notification in a Windows Phone app. This is my code:

public App() {
  // Global handler for uncaught exceptions.
  UnhandledException += Application_UnhandledException;

  // Standard XAML initialization
  InitializeComponent();

  // Phone-specific initialization
  InitializePhoneApplication();

  // Language display initialization
  InitializeLanguage();

  // Show graphics profiling information while debugging.
  if (Debugger.IsAttached) {
    // Display the current frame rate counters.
    Application.Current.Host.Settings.EnableFrameRateCounter = true;

    // Show the areas of the app that are being redrawn in each frame.
    //Application.Current.Host.Settings.EnableRedrawRegions = true;

    // Enable non-production analysis visualization mode,
    // which shows areas of a page that are handed off to GPU with a colored overlay.
    //Application.Current.Host.Settings.EnableCacheVisualization = true;

    // Prevent the screen from turning off while under the debugger by disabling
    // the application's idle detection.
    // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
    // and consume battery power when the user is not using the phone.
    PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
  }

  // Initialize the Parse client with your Application ID and .NET Key found on
  // your Parse dashboard

  ParseClient.Initialize("grpTmrClet8K35yeXg2HQKK8wl59VeC9ijH0I0dn", "os8EfSFq9maPBtDJ91Mq0xnWme8fLANhttTPAqKu");
  // After calling ParseClient.Initialize():
  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("testchannel");
  };


}

// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private async void Application_Launching(object sender, LaunchingEventArgs e) {
    await ParseAnalytics.TrackAppOpenedAsync();
}

When I send a push notification from the Parse dashboard it doesn't get received. I have tried running both on the emulator (Windows Phone 8.0) and device (8.1), with app in foreground, background and closed with the same negative result.

When I use a channel like "testchannel" above and use the segment options, the channel name appears in the dropdown list of options indicating that the app is at least connecting Parse, but it just wont receive the notifications.

Hope someone can help me identify what I am missing. Thanks in advance.


Solution

  • If you are developing a Windows Phone 8.1 app, make sure you've enabled toast notification in the manifest file. I don't quite understand everything about Parse just yet, but this is what works for me.

    In App.xaml.cs:

    public App()
        {
            this.InitializeComponent();
            this.Suspending += this.OnSuspending;
    
            ParseClient.Initialize("wSjuNTbtjVLRaedXvOoaf9S5cTbkuQohTulNZ2vS", "nWZMhXRet9Wotlgikb9aUdKf5GFtRiMvduw7w68z");
    
        }
    

    We subscribe and enable analytics OnLaunched:

    protected async override void OnLaunched(LaunchActivatedEventArgs e)
    //Generated codes go here
    await ParsePush.SubscribeAsync("testchannel");
    await ParseAnalytics.TrackAppOpenedAsync();
    

    That would simply do the trick. You should modify the code according to your needs. Hope this helps.