我在离子框架中做推送通知。我只是警觉。我需要收到通知。
我的javascript代码
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic', 'ionic.service.core','ngCordova', 'ionic.service.push'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(['$ionicAppProvider', function($ionicAppProvider) {
$ionicAppProvider.identify({
app_id: '38676e5c',
api_key: '76e051384cb6095e751db3791e26b2bd1162cceccd039f2a',
dev_push: true
});
}])
.controller('PushCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) {
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
alert('Success: ' + data.token);
console.log('name: ' + data.token + "--- Id: ");
console.log('Got token: ' , data.token, data.platform);
$scope.token = data.token;
});
$scope.identifyUser = function() {
var user = $ionicUser.get();
if (!user.user_id) {
user.user_id = $ionicUser.generateGUID();
}
angular.extend(user, {
name: 'My Name',
bio: 'I am awesome'
});
$ionicUser.identify(user).then(function() {
$scope.identified = true;
console.log('name: ' + user.name + "--- Id: " + user.user_id);
});
};
$scope.pushRegister = function() {
$ionicPush.register({
canShowAlert: true,
canSetBadge: true,
canPlaySound: true,
canRunActionsOnWake: true,
onNotification: function(notification) {
// handle your stuff
return true;
}
});
};
});
我的服务器代码
curl -u b81bb9cdc8ed06236804524c8e9b59ccc001900cd22f3c65: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: 38676e5c" https://push.ionic.io/api/v1/push -d '{"tokens": ["DEV-83f6de08-18fc-4bd9-9acd-72f974c2958a"],"production": false, "notification":{ "alert":"asasdsasd", "title": "demo", "android": {"payload": {"title": "hello","message": "hello"}}, "ios": {"payload": {"title": "hello","message": "hello"}}}}'
我的输出
我的问题是
我只是警觉(不通知) 设备令牌每秒都在变化..
我需要什么?
我需要在通知栏中获取推送通知..
我需要唯一的设备令牌..(id)..
答案 0 :(得分:0)
在你的离子app.js控制器中试试这个
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
//Ionic.io();
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log(token);
console.log("Device token:",token.token);
tokenapp = token.token;
console.log(tokenapp);
});
});
})