Using Pushwoosh with Inoc 2

Answered

Comments

4 comments

  • Avatar
    Nikolai Polkhovskiy

    Hi!

    That's actually quite strange. Could you please check whether you've carefully followed the guide?

    Also, may I ask you to try our Sample Application:

    https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/tree/master/Ionic

  • Avatar
    Rainer Oechsle

    Hi Nicolai,

    thanks for your quick answer!

    I'm pretty sure that I followed the guide. By your sample application, after a npm install and a gulp build I get a Error: 404 status code downloading 32-bit node.lib for builing node.sass Nvertheless I can run the App in the browser via ionic serve, but in Chrome Debugger, I can see that cordova has no instance (same problem as described in my first post).

    Back to my app: Through declare var cordova:any; I got rid of the compile error, but then I get a runntime error: cordova is not defined For better understanding I paste the entire code of my current app.ts

    'use strict';

    import {App, IonicApp, Platform} from 'ionic-angular'; import {LoginPage} from './pages/login/login'; import {HomePage} from './pages/home/home'; declare var cordova:any;

    @App({ templateUrl: 'build/app.html', config: {} // http://ionicframework.com/docs/v2/api/config/Config/ }) export class IwiiAngularApp { private rootPage: any; private pages: Array<{ title: string, component: any }>; private app: IonicApp; private platform: Platform;

    constructor(app: IonicApp, platform: Platform) { this.app = app; this.platform = platform; this.rootPage = LoginPage;

    this.initializeApp();
    
    // set our app's pages
    this.pages = [
      { title: 'Login', component: LoginPage },
      { title: 'Home', component: HomePage },
    ];
    

    }

    private initializeApp() { this.platform.ready().then(() => { // The platform is now ready. Note: if this callback fails to fire, follow // the Troubleshooting guide for a number of possible solutions: // // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. // // First, let's hide the keyboard accessory bar (only works natively) since // that's a better default: // // Keyboard.setAccessoryBarVisible(false); // // For example, we might change the StatusBar color. This one below is // good for dark backgrounds and light text: // StatusBar.setStyle(StatusBar.LIGHT_CONTENT) this.initPushwoosh(); }); }

    public initPushwoosh() { var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");

      //set push notifications handler
      document.addEventListener('push-notification', function (event) {
        //var title = event.notification.title;
        //var userData = event.notification.userdata;
        var title = "Titel";
        var userData = "Userdata Text";
        if (typeof(userData) != "undefined") {
          console.warn('user data: ' + JSON.stringify(userData));
        }
    
        alert(title);
      });
    
      //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", pw_appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
    pushNotification.onDeviceReady({projectid: "XXXXXXXXXXX", pw_appid: "XXXXX-XXXXX"});
    
      //register for pushes
       pushNotification.registerDevice(
          function (status) {
            var pushToken = status;
            console.warn('push token: ' + pushToken);
          },
          function (status) {
            console.warn(JSON.stringify(['failed to register ', status]));
          }
      );
    }
    

    }

  • Avatar
    Rainer Oechsle

    Hi,

    I've found the solution: If you run the app via ionic serve, the cordova.js is not loaded (correctly). But if you run it with e.g. ionic run browser it works :-)

  • Avatar
    Nishanth Kabra

    I have implemented push notifications in ionic2 app. You can see a live demo and implementation steps here. Live demo and implementation steps

Please sign in to leave a comment.