【发布时间】:2016-11-30 17:18:12
【问题描述】:
在我的 ionic 应用程序中,在浏览器中运行应用程序时出现以下错误
ng-cordova.js:6378 Uncaught ReferenceError: PushNotification is not defined
在我的控制台中,以及当我为 android 构建应用程序并在我的手机中运行时,它在那里也不起作用,即没有弹出窗口
注册 ID:alert(data.registrationId);。
app.run(function($ionicPlatform, $cordovaPushV5) {
$ionicPlatform.ready(function() {
// For Push Notification
var options = {
android: {
senderID: "121XXXXXXX49"
},
ios: {
alert: "true",
badge: "true",
sound: "true"
}
};
// initialize
$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(data) {
// `data.registrationId` save it somewhere;
alert(data.registrationId);
})
});
// triggered every time notification received
$rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){
alert(data.title + ' - '+ data.message);
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
});
// triggered every time error occurs
$rootScope.$on('$cordovaPushV5:errorOcurred', function(event, e){
alert(e.message);
// e.message
});
});
})
【问题讨论】:
标签: ionic-framework cordova-plugins ngcordova