【发布时间】:2016-10-06 06:53:10
【问题描述】:
我正在使用 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****/
【问题讨论】:
-
您是否在控制器中注入了
$cordovaPushV5?您是否将ngCordova.plugins.push_v5模块作为依赖项添加到您的应用中? -
@RaviTeja 我注入了它,代码在里面:
.run(function ($rootScope,$cordovaPushV5,$ionicPlatform, $state, AuthService, AUTH_EVENTS) { //Code here }我没有添加依赖,但是我安装了 ngCordova。请问如何添加?
标签: angularjs cordova ionic-framework