我正在通过ionic开发一个推送应用程序。我遵循了ionic本身的教程:http://docs.ionic.io/docs/push-from-scratch
注册用户-完美运行!但是设置推送通知没有生效。
两周前,它实际上完美地运作,可以做到我想要的一切。我认为ngCordova/ionic中出现了一些破坏性的变化,但我找不到原因。
错误信息:
跟踪
我更新了 Cordova,添加和删除了 Ionic ready 监听器。我尝试在手机上运行它,但出现了这个错误: 你有什么建议吗?
两周前,它实际上完美地运作,可以做到我想要的一切。我认为ngCordova/ionic中出现了一些破坏性的变化,但我找不到原因。
错误信息:
Cannot read property 'pushNotification' of undefined
at line: $ionicPush.register({
跟踪
TypeError: Cannot read property 'pushNotification' of undefined
at Object.register (ng-cordova.js:6362)
at init (ionic-push.js:146)
at ionic-push.js:309
at new Q (ionic.bundle.js:22259)
at Q (ionic.bundle.js:22246)
at Object.register (ionic-push.js:270)
at Scope.$scope.pushRegister (controllers.js:60)
at $parseFunctionCall (ionic.bundle.js:21172)
at ionic.bundle.js:53674
at Scope.$get.Scope.$eval (ionic.bundle.js:23228)
代码(controllers.js)如下:
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) {
// // Handles incoming device tokens
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
alert("Successfully registered token " + data.token);
console.log('Ionic Push: Got token ', data.token, data.platform);
$scope.token = data.token;
});
// // Identifies a user with the Ionic User service
$scope.identifyUser = function() {
console.log('Ionic User: Identifying with Ionic User service');
var user = $ionicUser.get();
if(!user.user_id) {
// Set your user_id here, or generate a random one.
user.user_id = $ionicUser.generateGUID();
};
// Add some metadata to your user object.
angular.extend(user, {
name: 'Ionitron',
bio: 'I come from planet Ion'
});
// Identify your user with the Ionic User Service
$ionicUser.identify(user).then(function(){
$scope.identified = true;
alert('Identified user ' + user.name + '\n ID ' + user.user_id);
});
};
$scope.pushRegister = function() {
console.log('Ionic Push: Registering user');
alert('bla');
// Register with the Ionic Push service. All parameters are optional.
$ionicPush.register({ //ERROR FIRES HERE
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification) {
// Handle new push notifications here
// console.log(notification);
return true;
}
});
alert('bla2');
};
})
我更新了 Cordova,添加和删除了 Ionic ready 监听器。我尝试在手机上运行它,但出现了这个错误: 你有什么建议吗?