Windows Phone应用程序未收到Parse.com的推送通知

时间:2014-12-30 10:59:52

标签: windows-phone-8 parse-platform push-notification mpns

我已经关注this tutorial在Windows Phone应用中设置Parse推送通知。这是我的代码:

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

当我从Parse仪表板发送推送通知时,它不会收到。我尝试在模拟器(Windows Phone 8.0)和设备(8.1)上运行,app在前台,后台并关闭,但结果相同。

当我使用像" testchannel"这样的频道时在上面并使用段选项,通道名称出现在选项的下拉列表中,表明该应用程序至少连接了Parse,但它只是不会收到通知。

希望有人能帮助我找出我所缺少的东西。提前谢谢。

1 个答案:

答案 0 :(得分:1)

如果您正在开发Windows Phone 8.1应用程序,请确保您已在清单文件中启用了Toast通知。 我还没有完全理解关于Parse的一切,但这对我有用。

在App.xaml.cs中:

public App()
    {
        this.InitializeComponent();
        this.Suspending += this.OnSuspending;

        ParseClient.Initialize("wSjuNTbtjVLRaedXvOoaf9S5cTbkuQohTulNZ2vS", "nWZMhXRet9Wotlgikb9aUdKf5GFtRiMvduw7w68z");

    }

我们订阅并启用分析OnLaunched:

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

那就是诀窍。您应该根据需要修改代码。希望这会有所帮助。