taivo / parse-push-plugin

Push notification plugin for Cordova/Phonegap/ionic on Parse platform
118 stars 102 forks source link

UnhandledPromiseRejectionWarning #126

Open simonj82 opened 6 years ago

simonj82 commented 6 years ago

Hi, i'm trying to use your plugin with Ionic 4. This is my app.component.ts file content:


import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { TabsPage } from '../pages/tabs/tabs';

declare var cordova:any;

@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  rootPage:any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    cordova.plugins.ParsePushPlugin.getInstallationId(function (id) {
      cordova.plugins.ParsePushPlugin.on('receivePN', function (pn) {
        console.log(pn);
      });
    });
  }
}

When I'm going to compile for iOS i've this output:

(node:27894) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:27894) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

But sometimes (I don't know why) it passes through that error, compile successfully for iOS and push notifications works perfectly.

Could you help me?

ghenry22 commented 6 years ago

Move your code calling the parsepush plugin to be on a new line immediately below the splashscreen.hide. You need to wait for platform.ready to fire before calling any Cordova plugins.

The way you have it now it isn’t waiting for platform.ready so if you call it too early it will fail.