【发布时间】:2016-04-27 07:52:17
【问题描述】:
我正在 ionic 框架中进行推送通知。我只有警觉。我需要收到通知。
我的 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)..
【问题讨论】:
-
为了获得设备令牌,请参考stackoverflow.com/questions/36717556/…
-
谢谢@mohan ...我也试过了..它会抛出这个错误“Ionic.User.anonymousId(); is undefined”,并将一些虚拟数字设置为用户ID。它不会在 ionic.io 中创建用户 ..如果你有输出,请将该包发送给我(balakumaran.raji@gmail.com)
-
在你的问题中你问你需要设备令牌堆栈溢出作为解决方案,然后要获得离子推送通知你需要 api 和 sederid 那么你的错误是什么
-
查看我的输出...我收到警报格式的通知..我没有收到通知...这是我的问题..我尝试了所有方法我没有得到任何输出跨度>
标签: ionic-framework