Hey Ionic community,
I’m trying to get the native push plugin to work in a small app.
I have installed the plugin with ionic plugin add phonegap-plugin-push --variable SENDER_ID="myid" and now I’m trying to initialise it in my app.ts like this:
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {HomePage} from './pages/home/home';
import {Push} from 'ionic-native';
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
rootPage: any = HomePage;
constructor(platform: Platform) {
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.
var push = Push.init({
android: {
senderID: "myappid"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
push.on('registration', function(data) {
console.log(data.registrationId);
});
});
}
}
This is my package.json.
When I try to test my app with ionic serveI get this error: EXCEPTION: Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'push.on') (apart from an error that es6-shim.map can’t be found but that one was there before and didn’t seems to influence my app).
How can I fix my problem (I hope this isn’t a stupid question)?
push.on('registration', (data) => {
if (data) {
console.log(data.registrationId);
} else {
console.log('No data returned.');
}
});
About the second error (that es6-shim.map can’t be found), it seems to appear only in Safari:
tlancina: Just to reassure everyone, this doesn’t break anything, it’s just Safari failing to find the sourcemap for es-shim.js, not sure why it only happens on Safari.
Thank you for your fast answer.
When I change my code as you suggested the error message stays the same, sorry. Could it be that the push plugin can’t be tested in the browser view?
EDIT: Interesting, when I test the app on my phone by using ionic run android the registration works fine. Strange …
Thanks for the information about the es6-shim problem.
Ah, yes, my mistake - you have to test it on a real device. You could check out Ionic Push then. It should work in browser too(i.e. it can be used for testing during development):
Limited pushes aren’t native push notifications, and are meant for testing against our API. They’ll work in a browser or emulator, but won’t arrive when your app is minimized, and the tokens won’t last more than 2 hours.
Hi. I am using real ios device for testing but getting this error: Please guide
[273:21956] Apache Cordova native platform version 4.2.1 is starting.
[273:21956] Multi-tasking -> Device: YES, App: YES
[273:21956] Using UIWebView
[273:21956] [CDVTimer][handleopenurl] 0.172973ms
...
[273:21956] not coldstart
[273:21956] active
[273:21956] PushPlugin skip clear badge
[273:21956] Resetting plugins due to page load.
...
[273:21956] DEVICE READY FIRED AFTER 1806 ms
[273:21956] EXCEPTION: Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'this.push.on')
[273:21956] ERROR: EXCEPTION: Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'this.push.on')
[273:21956] ERROR: STACKTRACE: