推送通知未显示在离子状态(Push notification not showing in ionic)

编程入门 行业动态 更新时间:2024-10-25 02:24:17
推送通知未显示在离子状态(Push notification not showing in 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)..

I'm doing push notification in ionic framework. I getting only alert. I need to get notification.

My javascript code

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

my server code

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"}}}}'

My output

My output

My problem is

I only getting alert(not notification) Device token changing every second..

What i need ??

I need to get push notification in notification bar..

I need unique device token..(id)..

最满意答案

在你的离子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); }); }); })

try this one in your ionic app.js controller

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

更多推荐

本文发布于:2023-08-01 05:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1353889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:离子   状态   通知   Push   showing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!