1

我正在實施推送通知離子平臺(離子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); 

爲了得到更多的信息,設備ID看this

看這樣的回答,我已經貼到與GCM推送通知達成協議Ionic Push Notifications: getPushPlugin is undefined

+0

可以發送代碼到 –

+0

什麼代碼??????? –

+0

1>註冊應用程序推服務,也 –