Hello I am new to Ionic.
I want to use ionic push notification for android phone.
I followed all the instruction from [ionic website][1] and [this][2]
For the debugging, I typed ionic serve
And I saw
“Uncaught ReferenceError: PushNotification is not defined”
in Chrome console.
Of course, notification is not working.
What am I missing ?
Any comment would be very helpful.Thank you.
Below is What I have done
I have put below code in terminal
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push
ionic io init
My ionic config info
dev_push is false,
There is 'app_id'
There is 'api_key'
There is 'gcm_key'
NodeJS
v5.2.0 (I tried also v4.2.2)
Ionic cli
v1.7.12
Below code is in $ionicPlatform.ready
var io = Ionic.io();
var user = Ionic.User.current();
if (!user.id) {
user.id = Ionic.User.anonymousId();
};
// Just add some dummy data..
user.set('name', 'moka');
user.set('bio', 'This is my little bio');
user.save();
var push = new Ionic.Push({
"onNotification": function(notification) {
alert('Received push notification!');
},
"pluginConfig": {
"android": {
"iconColor": "#0000FF"
}
}
});
var callback = function(data) {
push.addTokenToUser(user);
user.save();
};
push.register(callback);
// Edit
I changed form
ionic config set dev_push false
to
ionic config set dev_push true
It does not show no longer
“Uncaught ReferenceError: PushNotification is not defined”
However I am not sure if it’s correct way.
Because it was written on [this tutorial][2]
to turn off your development mode
ionic push --google-api-key your-google-api-key
ionic config set gcm_key your-gcm-project-number
ionic config set dev_push false
So it does not matter “Uncaught ReferenceError: PushNotification is not defined”, if I want to test on real android device ?
[1]: Ionic Docs - Ionic Documentation
[2]: https://devdactic.com/android-push-notifications/