我已经检查了相同问题的所有解决方案。但仍然无法解决问题。我正在使用visual studio和cordova应用程序。 添加了phonegap-plugin-push并添加了相应的代码。使用ngCordova $ cordovapushV5。获取未定义错误的PushNotification,我已检查物理设备并尝试了Android版本5.1和6.2.1。 按以下顺序添加了脚本文件。
<script src="scripts/angular.js"></script>
<script src="scripts/ng-cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
app.run(function ($http, $cordovaPushV5) {
var options = {
android: {
senderID: "xxxxxx"
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
};
// 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 (registrationId) {
// save `registrationId` somewhere;
})
});
// triggered every time notification received
$rootScope.$on('$cordovaPushV5:notificationReceived', function (event, data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
alert(data.message);
});
// triggered every time error occurs
$rootScope.$on('$cordovaPushV5:errorOcurred', function (event, e) {
// e.message
alert(e.message)
});
});