Unhandled Promise rejection: push.on is not a function

I am using Ionic 2.

I get this error when trying to set up push notifications. I copied this sample code from a tutorial, so I expected it to work. I must have something wrong. Any ideas:

Unhandled Promise rejection: push.on is not a function ; Zone: angular ; Task: Promise.then ; Value: TypeError: push.on is not a function push.on('registration', function (data) { 

typescript

 import { Push } from 'ionic-native'; 

. .

  pushNotifications(): void { var push = Push.init({ android: { vibrate: true, sound: true, senderID: "xxxxxxxxxxxxxxxxxxx" }, ios: { alert: "true", badge: true, sound: 'false' }, windows: {} }); push.on('registration', (data) => { console.log(data.registrationId); alert(data.registrationId.toString()); }); push.on('notification', (data) => { console.log(data); alert("Hi, Am a push notification"); }); push.on('error', (e) => { console.log(e.message); }); } 
+6
source share
1 answer

Be sure to check if "window.cordova" is available before using the plugin. Are you really testing the device or in the browser? Cordoba is not available in the browser.

EDIT To make sure your code editor knows what window.cordova is, make sure you install the typical cordons.

 npm install typings -g typings install dt~cordova --save --global 
0
source

All Articles