2015-08-25 5 views
0

У меня проблема с Ionic framework. Я следую руководству, чтобы получать и отправлять push-уведомление, но что-то не работает.Ионный каркас не сохраняет токен

Когда я запускаю приложение, я нажимаю кнопку «Идентифицировать» и показываю свое предупреждение, в котором указан идентификатор пользователя. После этого я нажимаю на кнопку регистрации, телефон показывает мне предупреждение, содержащее токен устройства (ANDROID). Но когда я иду на ionic.io, в панели инструментов моего приложения токена устройства нет.

Если у меня нет маркера, сохраненного на моей приборной панели, я не могу отправить push-уведомление. Кто-нибудь может мне помочь?

Это мой controller.js:

angular.module('starter.controllers', []) 

.controller('DashCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) { 

// 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); 
    }); 
    }; 

    $rootScope.$on('$cordovaPush:tokenReceived', function(event, data) { 
    console.log('Got token', data.token, data.platform); 
    // Do something with the token 
}); 

    // Registers a device for push notifications and stores its token 
    $scope.pushRegister = function() { 

    console.log('Ionic Push: Registering user'); 

    // Register with the Ionic Push service. All parameters are optional. 
    $ionicPush.register({ 
     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; 
     } 
    }); 
    }; 

    // 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; 
    }); 

}) 



.controller('ChatsCtrl', function($scope, Chats) { 
    // With the new view caching in Ionic, Controllers are only called 
    // when they are recreated or on app start, instead of every page change. 
    // To listen for when this page is active (for example, to refresh data), 
    // listen for the $ionicView.enter event: 
    // 
    //$scope.$on('$ionicView.enter', function(e) { 
    //}); 

    $scope.chats = Chats.all(); 
    $scope.remove = function(chat) { 
    Chats.remove(chat); 
    }; 
}) 

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) { 
    $scope.chat = Chats.get($stateParams.chatId); 
}) 

.controller('AccountCtrl', function($scope) { 
    $scope.settings = { 
    enableFriends: true 
    }; 
}); 

Я следую ионному руководству шаг за шагом

+0

У меня такая же проблема. – mikeLspohn

+0

Я решаю проблему, используя PARSE – Michael

ответ

0

Для того, чтобы получить доступ к фишке на ionic.io, вы должны протолкнуть:

var push = new Ionic.Push(); 
var user = Ionic.User.current(); 

var callback = function(pushToken) { 
    console.log('Registered token:', pushToken.token); 
    user.addPushToken(pushToken); 
    user.save(); // you NEED to call a save after you add the token 
} 

push.register(callback); 

как упомянуто в docs.

Смежные вопросы