1

Я внедряю push-уведомление мое уведомление о push с ионной платформой (ионной io), работая правильно, теперь я должен вынуть этот токен устройства и отправить его на свой сервер.
ниже мой ap.js код:Ионное толкование внедрения

var push = new Ionic.Push({ 
     "debug": true 
    }); 

    push.register(function(token) { 
     console.log("My Device token:",token.token); 
     push.saveToken(token); // persist the token in the Ionic Platform 

    }); 

Это мой Логин для

$scope.login = function() { 
$http({ 
method: "post", 
url: "http://200.189.253.200:8081/employee-connect/oauth/token", 
data: "username="+$scope.username+"&password="+$scope.password+"&grant_type=password&scope=read write&client_secret=my-secret-token-to-change-in-production&client_id=employeeConnectapp2", 
withCredentials: true, 
headers: { 
'Content-Type': 'application/x-www-form-urlencoded' 
} 
}) 
.success(function (data){ 
window.localStorage.setItem("token_type", data.token_type); 
window.localStorage.setItem("token", data.access_token); 
$state.go('tabsController.home'); 
}) 
.error(function(data) { 
var alertPopup = $ionicPopup.alert({ 
title: 'Login failed!', 
template: 'Please check your credentials!' 
}); 
}); 
} 

В вызове успеха я должен послать маркер, запрашивая его из консоли, но не знаю, как делать. Пожалуйста, помогите мне.

ответ

1

Установите этот плагин

cordova plugin add https://github.com/phonegap-build/PushPlugin.git 

и внутри .run Funtion сделать это

  var androidConfig = { 
      "senderID": "xxxxxxxx", //you should place your gcm project number 
      }; 

      document.addEventListener("deviceready", function(){ 
      $cordovaPush.register(androidConfig).then(function(result) { 
       // Success 
      }, function(err) { 
       // Error 
      }) 

      $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) { 
       switch(notification.event) { 
       case 'registered': 
        if (notification.regid.length > 0) { 
        alert('registration ID = ' + notification.regid); 
    //here you will see the device token in alert. 

        MyService.setDeviceID(notification.regid); 

//here i have used MyService to access the regiser id inside my controller 
        } 
        break; 

       case 'message': 
        // this is the actual push notification. its format depends on the data model from the push server 
        alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt); 
        break; 

       case 'error': 
        alert('GCM error = ' + notification.msg); 
        break; 

       default: 
        alert('An unknown GCM event has occurred'); 
        break; 
       } 
      }); 



      }, false); 

Для получения дополнительной информации о получении идентификатор устройства выглядят this

Посмотрите этот ответ, который я отправил к получить Сделку с уведомлением о толчке GCM Ionic Push Notifications: getPushPlugin is undefined

+0

может отправить код на –

+0

Какой код ??????? –

+0

1> зарегистрировать приложение для push-сервисов, а также –

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