Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Push notification 离子2问题:没有推送的提供程序_Push Notification_Google Cloud Messaging_Ionic2 - Fatal编程技术网

Push notification 离子2问题:没有推送的提供程序

Push notification 离子2问题:没有推送的提供程序,push-notification,google-cloud-messaging,ionic2,Push Notification,Google Cloud Messaging,Ionic2,在我的Ionic 2项目中,我有下面的代码,它应该接收推送通知。当我运行代码时,我在控制台中不断得到一个错误,说没有Push的提供程序 import { Component, ViewChild } from '@angular/core'; import { ionicBootstrap, Platform, Nav } from 'ionic-angular'; import { StatusBar, Splashscreen} from 'ionic-native'; import { C

在我的Ionic 2项目中,我有下面的代码,它应该接收推送通知。当我运行代码时,我在控制台中不断得到一个错误,说没有Push的提供程序

import { Component, ViewChild } from '@angular/core';
import { ionicBootstrap, Platform, Nav } from 'ionic-angular';
import { StatusBar, Splashscreen} from 'ionic-native';
import { CloudSettings, PushToken, Push } from '@ionic/cloud-angular';

@Component({
  templateUrl:'build/app.html'
})

constructor(public platform: Platform, private userProvider: UserProvider, public push: Push) {const cloudSettings: CloudSettings = {
    'core': {
      'app_id': 'XXXXXXX',
    },
    'push': {
      'sender_id': 'XXXXXXX',
      'pluginConfig': {
        'android': {
          'iconColor': '#343434'
        }
      }
    }
  };

  this.push.register().then((t: PushToken) => {
      return this.push.saveToken(t);
    }).then((t: PushToken) => {
      console.log('Token saved:', t.token);
    });

  this.push.rx.notification()
    .subscribe((msg) => {
      alert(msg.title + ': ' + msg.text);
    });

});
我认为这是某种离子2版本的不匹配,下面是我的离子信息详细信息

Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.11
Ionic CLI Version: 2.0.0
Ionic App Lib Version: 2.0.0-beta.20
OS: Distributor ID:     Ubuntu Description:     Ubuntu 14.04.3 LTS 
Node Version: v4.5.0
我解决了错误“Push没有提供程序”(使用本地推送系统,而不是ionic cloud),推送设置是在自定义提供程序中完成的(不是直接在app.component.ts中)

  • 在app.module.ts中(错误的原因是缺少提供程序)
  • 从'@ionic native/Push'导入{Push}; ... 供应商:[ 推 ... ]
  • 在提供程序中,在platform.ready()中初始化推送(以确保插件已准备就绪)
  • this.platform.ready()。然后(()=>{ ... this.pushObject=this.push.init(选项); });
    首先,我会考虑错误消息所说的内容,并检查我是否确实在我的提供者列表中声明了PushNgModule@JBNizet添加了检查我的编辑不,你没有。您的问题中没有NgModule。Angular 2应用程序是一个用
    @NgModule({…})
    修饰的类。这基本上就是你配置应用程序的地方。显示代码。
    @NgModule({
    
      declarations: [
        MyApp,
        AboutPage,
        ContactPage,
        HomePage,
        TabsPage
      ],
    
      imports: [
    
        IonicModule.forRoot(MyApp),
        CloudModule.forRoot(cloudSettings)
      ],
    
    import { Push } from '@ionic-native/push'; ... providers: [ Push, ... ] this.platform.ready().then(() => { ... this.pushObject = this.push.init(options); });