我創建了IONIC 2應用程序,在最後階段,我試圖實施IONI雲推,但它不工作,每當我啓用雲推寄存器功能時,應用程序崩潰:IONIC 2雲推不工作 - 應用程序崩潰
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t);
}).then((t: PushToken) => {
console.log('Token saved:', t.token);
});
我正在使用「的Android離子跑」構建在我真正的設備
請幫助我什麼,我做錯了。已經檢查了很多文章,它說我已經實施了相同的過程: -
npm install @ionic/cloud-angular --save
cordova plugin add phonegap-plugin-push --variable SENDER_ID=12341234 --save
ionic io init
和所有其他配置。
下面是我app.component.ts
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, ToastController } from 'ionic-angular';
import { Events } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { Storage } from '@ionic/storage';
import { TabsComponent } from '../pages/tabs/tabs-component/tabs.component';
import { LoginComponent } from '../pages/login/login-component/login.component';
import { Push, PushToken } from '@ionic/cloud-angular';
//import { Push } from 'ionic-native';
//import { CloudSettings, CloudModule } from '@ionic/cloud-angular';
//import { Push, PushObject, PushOptions } from "@ionic-native";
@Component({
templateUrl: './app.html',
})
export class BanglaliveApp {
@ViewChild(Nav) nav: Nav;
rootPage = TabsComponent;
user: any;
pages: Array<{title: string, component: any, category: any}>;
constructor(
public push: Push,
public platform: Platform,
private storage: Storage,
private toastController: ToastController,
public events: Events
) {
this.initializeApp();
events.subscribe('userloggedin', user => {
if(user){
this.user = user;
}
});
storage.get('wordpress.user').then((value) => {
if (value) {
this.user = value;
}
});
this.pages = [
{ title: '????? ????', component: TabsComponent, category: { class:'home' }},
{ title: '?????????', component: LoginComponent, category: {class: 'category'}}
];
}
initializeApp() {
this.platform.ready().then(() => {
// Enable RTL Support
// this.platform.setDir('rtl', true);
StatusBar.styleDefault();
Splashscreen.hide();
// ############## P U S H ###############
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);
// });
// ############## P U S H ###############
});
}
openPage(page, index) {
//check if page or post has been called
this.nav.setRoot(page.component);
}
}
login(){
this.nav.push(LoginComponent);
}
logout() {
this.user = undefined;
this.storage.remove('wordpress.user');
this.nav.setRoot(LoginComponent);
}
profile() {
this.nav.push(ProfilePage);
}
}
這裏是我app.module.ts: -
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { SharedModule } from './shared/shared.module'
import { TabsModule } from '../pages/tabs/tabs.module';
import { SignUpModule } from '../pages/signup/signup.module'; //SSSS
import { ProfileModule } from '../pages/profile/profile.module'; //SSSS
import { MyApp} from './app.component';
import { CloudSettings, CloudModule } from '@ionic/cloud-angular';
const cloudSettings: CloudSettings = {
'core': {
'app_id': 'XXXXXX',
},
'push': {
'sender_id': 'XXXXXXXX',
'pluginConfig': {
'ios': {
'badge': true,
'sound': true
},
'android': {
'iconColor': '#343434'
}
}
}
};
@NgModule({
declarations: [
MyApp
],
imports: [
IonicModule.forRoot(MyApp, {
backButtonIcon: 'arrow-back'
}),
CloudModule.forRoot(cloudSettings),
SharedModule,
TabsModule,
SignUpModule,
ProfileModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}
請幫助.. !!
謝謝
你可以分享插件網址嗎? – Sampath
我認爲這一個 - https://github.com/phonegap/phonegap-plugin-push但我遵循離子文檔https://docs.ionic.io/services/push/ –
什麼是正確的方法? @suraj –