Push notification 离子2问题:没有推送的提供程序
在我的Ionic 2项目中,我有下面的代码,它应该接收推送通知。当我运行代码时,我在控制台中不断得到一个错误,说没有Push的提供程序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
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中)
首先,我会考虑错误消息所说的内容,并检查我是否确实在我的提供者列表中声明了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);
});