我正在使用cordovaPushV5插件,以便能够在我的应用上实现推送通知。
我正如本教程中所做的那样:https://github.com/yafraorg/yafra/wiki/Blog-Ionic-PushV5
当我在浏览器上运行应用程序时,我在控制台中收到上述错误。
我正确安装了插件,并在我的App.js文件中包含了必要的代码行,如下所示。
有人能帮助我知道我哪里出错吗?
/****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****/

答案 0 :(得分:1)
在同一条船上航行。在我的index.html
文件中看到了一些遗漏的东西。我正在使用ionic
项目。
<!-- 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">
如果您看到ng-cordova.min.js
文件有两个文件夹。 lib/ngCordova/dist/ng-cordova.min.js
具有$cordovaPushV5
定义。
希望这有帮助。