2016-09-29 99 views
1

我不理解Ionic Cloud文档让这个声音很容易,但我似乎无法接收推送通知。它会在应用程序启动时进行注册,但在此之后,从Ionic Cloud仪表板发出的通知从未收到。我花了数小时试图找到我在文档中错过的关键词。我还审查了FAQ,并通过发送第二次通知并结束申请,并且每次状态为sent,但我表示应该仍然收到申请中的第一个通知。Ionic Cloud Push未接收到GCM通知

我正在向所有用户发送通知,但我们没有使用Ionic Clouds Auth服务,所以我不确定通知是如何定向的,因为没有用户只是使用应用程序加载的注册设备ionic run android

使用干净安装离子1.3.1的我已经做了最低限度,以接收基于文档的通知,任何人都可以看到我可能踩错了吗?这只是基本的设置与控制器来监听通知。

继续按照Ionic文档一步一步。我完全重新编写应用程序,只是使用这些确切的步骤来编写这个问题。

  1. npm install @ionic/cloud --save
  2. cp node_modules/@ionic/cloud/dist/bundle/ionic.cloud.min.js www/lib
  3. 添加云JS文件index.html的,我将在后下)
  4. 不需要为蓝鸟承诺
  5. ionic io init在仪表板创建应用程序,设置在APP_ID ionic.config.json,我将在后下
  6. 加配置块,我将在下面发布,并跃升至推送服务
  7. 不得不设立GCM因为FCM不离子云仪表板可由于一些问题
  8. 增添了安全配置文件,以使用证书
  9. 新增的GCM凭据发展安全配置
  10. 的离子云仪表盘的应用
  11. 新增phonegap-plugin-push使用cordova plugin add phonegap-plugin-push --variable SENDER_ID=123456789011 --save,并检查SENDER_ID是在​​3210,其中SENDER_ID是项目数
  12. 新增ionic.cloud作为依赖于模块
  13. 添加运行用于注册该设备令牌,该令牌我会后下面
  14. 创建一个临时控制器只是用于测试,因为这是角1.5,你只要现在可以创建一个组件,并增加了$范围。$监听者,我将在后下
  15. ionic run和加载应用程序到我的手机,其上的应用程序运行检查时,我可以看到它是在开放注册,我得到令牌
  16. 然后到离子云仪表板和发送的通知,这是从来没有收到

注:的APP_ID,SENDER_ID,API_KEYS等已全部被取代为兰特omly当量数对于这个例子

索引。HTML

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 

    <!-- TODO: Add brand of application --> 
    <title></title> 

    <link rel="manifest" href="manifest.json"> 

    <!-- un-comment this code to enable service worker 
    <script> 
     if ('serviceWorker' in navigator) { 
     navigator.serviceWorker.register('service-worker.js') 
      .then(() => console.log('service worker installed')) 
      .catch(err => console.log('Error', err)); 
     } 
    </script>--> 


    <!-- Compiled Styles --> 
    <!-- inject:css --> 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    <!-- endinject --> 

    <!-- Ionic Scripts --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="lib/ionic.cloud.min.js"></script> 

    <!-- Google Maps API --> 
    <!--<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDOCZ0kgg2rTRzmGepWQMu6EM90koX4mUs&amp;libraries=places"></script>--> 

    <!-- Vendor Scripts --> 
    <!-- bower:js --> 
    <!-- endbower --> 

    <!-- Cordova Script (this will be a 404 during development) --> 
    <script src="lib/ngCordova/dist/ng-cordova.js"></script> 
    <script src="cordova.js"></script> 

    <!-- Compiled Scripts --> 
    <!-- inject:js --> 
    <script src="js/app.module.js"></script> 
    <script src="js/app.cloud.js"></script> 
    <script src="js/app.config.js"></script> 
    <script src="js/app.constants.js"></script> 
    <script src="js/app.controller.js"></script> 
    <!-- endinject --> 
    <!-- inject:templates:js --> 
    <!-- endinject --> 
</head> 
<body ng-app="app"> 

<ion-pane> 
    <ion-header-bar class="bar-stable" ng-controller="AppController"> 
     <h1 class="title">Ionic Blank Starter</h1> 
    </ion-header-bar> 
    <ion-content> 
    </ion-content> 
</ion-pane> 

</body> 
</html> 

app.module.js

(function() { 

    'use strict'; 

    var dependencies = [ 
    'ionic', 
    'ionic.cloud', 
    'ngCordova' 
    ]; 

    function run($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(); 
     } 
    }); 
    } 

    run.$inject = [ 
    '$ionicPlatform' 
    ]; 

    angular 
     .module('app', dependencies) 
     .run(run); 

})(); 

app.cloud.js

(function() { 

    'use strict'; 

    function config($ionicCloudProvider) { 

     $ionicCloudProvider.init({ 
      'core': { 
       'app_id': '1234ab12' 
      }, 
      'push': { 
       'sender_id': '123456789011', 
       'pluginConfig': { 
        'ios': { 
         'badge': true, 
         'sound': true 
        }, 
        'android': { 
         'iconColor': '#343434', 
         'sound': true, 
         'vibrate': true 
        } 
       } 
      } 
     }); 
    } 

    config.$inject = [ 
     '$ionicCloudProvider' 
    ]; 

    function run($ionicPush) { 

     // Register every time the application is opened so the device is 
     // guaranteed to be registered and ready for notifications 
     $ionicPush 
      .register() 
      .then(function (token) { 

       // Save the generated device token with the current user when 
       // the token is saved 
       return $ionicPush.saveToken(token); 
      }) 
      .then(function (device) { 

       console.log('Device token:', device.token); 
      }); 
    } 

    run.$inject = [ 
     '$ionicPush' 
    ]; 

    angular 
     .module('app') 
     .config(config) 
     .run(run); 

})(); 

ionic.config.json

{ 
    "name": "v1.3", 
    "app_id": "1234ab12", 
    "gulpStartupTasks": [ 
    "sass", 
    "watch" 
    ], 
    "watchPatterns": [ 
    "www/**/*", 
    "!www/lib/**/*", 
    "!www/**/*.map" 
    ] 
} 

的config.xml

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.ionicframework.v13169294" version="0.0.1" 

    // ... 

    <plugin name="phonegap-plugin-push" spec="~1.8.2"> 
     <variable name="SENDER_ID" value="123456789011" /> 
    </plugin> 
</widget> 

.io.config.json

{"app_id":"1234ab12","api_key":"e38rj3i3jsofp3098e8djksod92dmdow0ekdsj2930dk300f"}

app.controller.js

(function() { 

    'use strict'; 

    function AppController($scope) { 

     var vm = this; 

     // --- 
     // PUBLIC METHODS. 
     // --- 

     $scope.$on('cloud:push:notification', function (event, data) { 
      var msg = data.message; 
      alert(msg.title + ': ' + msg.text); 
     }); 

     // --- 
     // PRIVATE METHODS. 
     // --- 
    } 

    AppController.$inject = [ 
     '$scope' 
    ]; 

    angular 
     .module('app') 
     .controller('AppController', AppController); 

})(); 

回答

0

好的,我在问题中设置的所有内容都是正确的。什么是不正确的是Ionic仪表板,它要求在安全配置文件中使用GCM API密钥,相反,您需要创建FCM项目并在GCM API密钥输入字段中使用服务器密钥。

感谢这篇文章在Ionics论坛 - https://forum.ionicframework.com/t/ionic-push-notification-for-android-keeps-giving-me-error-gcm-invalid-auth/63041/8

我还在Ionic Cloud的github回购上发布了一个问题 - https://github.com/driftyco/ionic-cloud-issues/issues/198#issuecomment-250856824