Ionischen 2 - Kein Anbieter für Push
War ich nach diesem tutorial: https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59 versucht zu implementieren push-Benachrichtigungen mit FB, ich glaube, ich habe alles richtig gemacht aber wenn ich jetzt meine app bekomme ich auch eine exception: Fehler :0:0 verursacht durch: Kein Anbieter für Push!
Jede Idee, wie kann ich es lösen?
Es ist meine app.Komponente.ts und app.- Modul.ts
app.- Modul.ts:
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
{Only App Pages ...}
@NgModule({
declarations: [
MyApp,
{Only App Pages ...}
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
{Only App Pages...}
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
App.Komponente.ts:
import {Component} from "@angular/core";
import {AlertController, Nav, Platform} from "ionic-angular";
import {StatusBar} from "@ionic-native/status-bar";
import {SplashScreen} from "@ionic-native/splash-screen";
import {Push, PushObject, PushOptions} from "@ionic-native/push";
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
public push: Push,
public alertCtrl: AlertController) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
this.initPushNotification();
});
}
initPushNotification() {
if (!this.platform.is('cordova')) {
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
const options: PushOptions = {
android: {
senderID: "883847118563"
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data: any) => {
console.log("device token ->", data.registrationId);
let alert = this.alertCtrl.create({
title: 'device token',
subTitle: data.registrationId,
buttons: ['OK']
});
alert.present();
});
pushObject.on('notification').subscribe((data: any) => {
console.log('message', data.message);
//if user using app and push notification comes
if (data.additionalData.foreground) {
//if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: 'New Notification',
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
//TODO: Your logic here
// this.nav.push(DetailsPage, {message: data.message});
}
}]
});
confirmAlert.present();
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
// this.nav.push(DetailsPage, {message: data.message})
let alert = this.alertCtrl.create({
title: 'clicked on',
subTitle: "you clicked on the notification!",
buttons: ['OK']
});
alert.present();
console.log("Push notification clicked");
}
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
}
Vielen Dank im Voraus für die Hilfe.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Müssen Sie
Push
als Anbieter in einer app.- Modul.tsIn Ionischen native v3.x, alle plugins werden als Leistungsträger und durch die Injektion in den Konstruktor.