Hey Everyone
this was probably asked a million times, but I couldn’t find an answer.
I am using ionic 2 with angular 2 (TypeScript) and Pushwoosh. Pushwoosh is set up properly and the device is registering and I am getting a token… all is good…
when I send a test woosh, I am, receiving the notification on the phone and the xCode shows a system trace when the woosh arrives., but the event listener is not fired on the typescript level… anyone knows where the problem might be?
here’s the code:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import {PushwooshService} from './services/pushwoosh.service';
@Component({
template: ` <ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>`
})
export class MyApp
{
constructor(platform: Platform , private _pushService:PushwooshService)
{
platform.ready().then(() => {
StatusBar.styleDefault();
_pushService.init();
});
}
}
and the service:
import {Injectable} from "@angular/core";
import {Device} from 'ionic-native';
declare var cordova : any;
var PUSHWOOSH_APP_ID = XXXXXXXXXXXXX';
var GOOGLE_PROJECT_NUMBER = 'XXXXXXXXXXXXX';
@Injectable()
export class PushwooshService
{
init()
{
console.log("PushwooshService init");
if(!Device.device) {
console.log("PushwooshService init: No device object available. Skipping init. (Probably not running in a deployed Cordova app.)");
return;
}
this.initIOS();
}
initIOS()
{
var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");
console.log("initIOS" , document);
//set push notification callback before we initialize the plugin
document.addEventListener('push-notification', function (event:any)
{
//get the notification payload
var notification = event.notification;
console.log('received notification: ', notification);
//clear the app badge
pushNotification.setApplicationIconBadgeNumber(0);
});
//initialize the plugin
pushNotification.onDeviceReady({pw_appid: PUSHWOOSH_APP_ID});
//register for pushes
pushNotification.registerDevice(
function (status)
{
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function (status)
{
console.warn('failed to register : ' + JSON.stringify(status));
alert(JSON.stringify(['failed to register ', status]));
}
);
//reset badges on app start
pushNotification.setApplicationIconBadgeNumber(0);
}
}
it’s the document.addEventListener(‘push-notification’, function (event:any) that is not being called.
any ideas where I might have gne wrong?