使用Firebase云消息传递的Ionic Native Push崩溃

时间:2016-10-31 15:21:34

标签: cordova phonegap-plugins ionic2 firebase-cloud-messaging

我正在使用Ionic2并正在使用Push Messaging构建聊天应用程序。我正在使用FCM(Firebase云消息传递)。我跟着使用following tutorial插件的phonegap-plugin-push,一切都运行良好。

我的电脑然后崩溃,我不得不重新安装我所有的Cordova插件。从那时起,Push Notifications导致应用程序崩溃。当我尝试初始化Push并调用以下代码时:

import { StatusBar, Push, SQLite } from 'ionic-native';
                    ...

            let push = Push.init({
              android: {
                senderID: "XXXXXXXXXXXXXX",
                topics: topics
              },
              ios: {
                alert: "true",
                badge: false,
                sound: "true",
                topics: topics
              },
              windows: {}
            });

我在日志中没有任何内容时收到以下错误:

enter image description here

如果我不使用Push它没有错误,但我显然想使用推送通知。

如果有人有任何建议,我将不胜感激。

我尝试过以下操作但没有成功:

  1. 重新安装所有Cordova插件
  2. 创建了一个新的FCM项目并使用了其SENDER_ID
  3. 删除&添加Android平台(ionic platform remove android& ionic platform add android
  4. 尝试重新安装Ionic Native(npm install ionic-native --save
  5. 更多信息:

    E:\Development\IDE\ionic-apps\theWhoZoo>cordova plugin list
    cordova-plugin-camera 2.2.0 "Camera"
    cordova-plugin-compat 1.0.0 "Compat"
    cordova-plugin-console 1.0.3 "Console"
    cordova-plugin-crop 0.1.0 "CropPlugin"
    cordova-plugin-device 1.1.2 "Device"
    cordova-plugin-geolocation 2.2.0 "Geolocation"
    cordova-plugin-network-information 1.3.0 "Network Information"
    cordova-plugin-splashscreen 3.2.2 "Splashscreen"
    cordova-plugin-statusbar 2.1.3 "StatusBar"
    cordova-plugin-whitelist 1.2.2 "Whitelist"
    cordova-sqlite-plugin 3.0.0 "Cordova SQLite Plugin"
    cordova-sqlite-storage 1.4.8 "Cordova sqlite storage plugin"
    ionic-plugin-keyboard 2.2.1 "Keyboard"
    phonegap-plugin-push 1.8.3 "PushPlugin"
    plugin.google.maps 1.3.9 "phonegap-googlemaps-plugin"
    

    npm install给了我以下内容:

    ...

    npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
    
    > node-sass@3.10.1 postinstall E:\Development\IDE\ionic-apps\theWhoZoo\node_modules\ionic-gulp-sass-build\node_modules\gulp-sass\node_modules\node-sass
    > node scripts/build.js
    
    "E:\Development\IDE\ionic-apps\theWhoZoo\node_modules\ionic-gulp-sass-build\node_modules\gulp-sass\node_modules\node-sass\vendor\win32-x64-48\binding.node" exists.
     testing binary.
    Binary is fine; exiting.
    npm ERR! Windows_NT 10.0.14393
    npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Richard\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
    npm ERR! node v6.2.2
    npm ERR! npm  v2.15.11
    npm ERR! code EPEERINVALID
    
    npm ERR! peerinvalid The package @angular/compiler@2.1.2 does not satisfy its siblings' peerDependencies requirements!
    npm ERR! peerinvalid Peer @angular/forms@0.2.0 wants @angular/compiler@^2.0.0-rc.4
    npm ERR! peerinvalid Peer @angular/platform-browser-dynamic@2.1.2 wants @angular/compiler@2.1.2
    npm ERR! peerinvalid Peer ionic-angular@2.0.0-rc.1 wants @angular/compiler@^2.0.0
    npm ERR! peerinvalid Peer @angular/platform-server@2.1.2 wants @angular/compiler@2.1.2
    npm ERR! peerinvalid Peer @angular/compiler-cli@0.6.4 wants @angular/compiler@2.0.2
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     E:\Development\IDE\ionic-apps\theWhoZoo\npm-debug.log
    

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

  1. 使用“phonegap-plugin-push 1.8.4”
  2. 请勿使用'ionic-native'中的原生“import {StatusBar,Push,SQLite};”
  3. 尝试使用'@ ionic / cloud-angular'中的import {Push,PushToken}; (youpage.ts)
  4. 从'@ ionic / cloud-angular'导入{CloudSettings,CloudModule}; (app.module.ts)

     const cloudSettings: CloudSettings = { 'core': {
                'app_id': 'xxx'
              },
              'push': {
                'sender_id': 'yyy',
                'pluginConfig': {
                  'ios': {
                    'badge': true,
                    'sound': true
                  },
                  'android': {
                    'iconColor': '#ff0000'
                  }
                }
              }
            };
    
  5. 它为我工作。