I was reading some questions about this error but nothing has worked for me.
I installed ngCordova and injected it in my angular.module(). Then I injected $cordovaPushV5 inside:
.run($ionicPlatform, $state, $cordovaPushV5, $ionicPopup){
$ionicPlatform.ready(function() {
onDeviceReady();
function onDeviceReady(){
var options = {
android: {
senderID: "************",
sound: true,
vibrate: true
},
browser: {},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
};
$cordovaPushV5.initialize(options).then(function() {
// start listening for new notifications
$cordovaPushV5.onNotification();
// start listening for errors
$cordovaPushV5.onError();
// register to get registrationId
$cordovaPushV5.register().then(function(registrationId) {
// save `registrationId` somewhere;
localStorage.setItem("token", registrationId);
console.log("token: "+registrationId);
})
});
// triggered every time notification received
$rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
});
// triggered every time error occurs
$rootScope.$on('$cordovaPushV5:errorOcurred', function(event, e){
// e.message
});
}
});
}
but it looks like PushNotifications cannot be initialized even after installing the plugin with cordova plugin add phonegap-plugin-push.
What´s wrong here?
fetch.json:
"phonegap-plugin-push": {
"source": {
"type": "registry",
"id": "phonegap-plugin-push@latest"
},
"is_top_level": true,
"variables": {
"SENDER_ID": "*************"
}
},
config.xml:
<plugin name="phonegap-plugin-push" spec="^2.0.0-rc5">
<variable name="SENDER_ID" value="************" />
</plugin>
package.json
"dependencies": {
"cordova-plugin-geolocation": "^2.4.3",
"phonegap-plugin-push": "^2.0.0-rc5"
},
"cordova": {
"plugins": {
"phonegap-plugin-push": {
"variables": {
"SENDER_ID": "***************"
}
},
"cordova-plugin-geolocation": {}
}
}
cordova --version 7.0.1
cordova platform version android 6.2.2
nodejs version 6.11.1
npm version 3.10.10
ionic version 3.5.0
git version 2.13.3.windows.1