我的Ionic 2项目中有以下代码,可以接收推送通知。当我运行代码时,我一直在控制台中收到错误提示没有提供者推送错误。
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
答案 0 :(得分:1)
我解决了错误“No Provider For Push”(使用本地推送系统,而非离子云),其中推送设置是在自定义提供程序中完成的(不是直接在app.component.ts中)
import { Push } from '@ionic-native/push'; ... providers: [ Push, ... ]
this.platform.ready().then(() => { ... this.pushObject = this.push.init(options); });
答案 1 :(得分:-1)
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
IonicModule.forRoot(MyApp),
CloudModule.forRoot(cloudSettings)
],