Reputation: 69
I am working with cordovaPushV5 plugin to be able to implement push notifications on my app.
I am doing exactly as in this tutorial: https://github.com/yafraorg/yafra/wiki/Blog-Ionic-PushV5
When I run the app on my browser, I get the above error in console.
I installed the plugin correctly and included the necessary lines of code in my App.js file as shown below.
Could someone help me know where I am going wrong?
/****ENABLE RECEIVING OF PUSH NOTIFICATIONS****/
/*
* start within Platform ready
*/
$ionicPlatform.ready(function() {
// register push notification and get local push token
localStorage.myPush = ''; // I use a localStorage variable to persist the token
$cordovaPushV5.initialize( // important to initialize with the multidevice structure !!
{
android: {
senderID: "704649974960"
},
ios: {
alert: 'true',
badge: true,
sound: 'false',
clearBadge: true
},
windows: {}
}
).then(function (result) {
$cordovaPushV5.onNotification();
$cordovaPushV5.onError();
$cordovaPushV5.register().then(function (resultreg) {
localStorage.myPush = resultreg;
// SEND THE TOKEN TO THE SERVER, best associated with your device id and user
}, function (err) {
// handle error
});
});
});
/*
* Push notification events
*/
$rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data) { // use two variables here, event and data !!!
if (data.additionalData.foreground === false) {
// do something if the app is in foreground while receiving to push - handle in app push handling
} else {
// handle push messages while app is in background or not started
}
if (Device.isOniOS()) {
if (data.additionalData.badge) {
$cordovaPushV5.setBadgeNumber(NewNumber).then(function (result) {
// OK
}, function (err) {
// handle error
});
}
}
$cordovaPushV5.finish().then(function (result) {
// OK finished - works only with the dev-next version of pushV5.js in ngCordova as of February 8, 2016
}, function (err) {
// handle error
});
});
$rootScope.$on('$cordovaPushV5:errorOccurred', function(event, error) {
// handle error
});
/****END ENABLE RECEIVING OF PUSH NOTIFICATIONS****/
Upvotes: 2
Views: 830
Reputation: 1031
Sailing in the same boat. Saw a couple of things missing from my index.html
file. I am using ionic
project.
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic-service-core/ionic-core.js"></script>
<script src="lib/ionic-service-push/ionic-push.js"></script>
<!-- ngCordova -->
<script src="lib/cordova/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.min.js">
If you see the there are two folders for ng-cordova.min.js
file. The lib/ngCordova/dist/ng-cordova.min.js
has the $cordovaPushV5
definition.
Hope this helps.
Upvotes: 1