Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Firebase Plugin not installed

I created a new ionic project and added firebase to this, but everytime I do an ionic serve -c and open the DevApp, I see in the console following errors:

  • Ionic Native: tried calling Firebase.subscribe, but the Firebase plugin is not installed.
  • Install the Firebase plugin: 'ionic cordova plugin add cordova-plugin-firebase'

Ionic info:

 ionic (Ionic CLI)  : 4.1.2 (C:\Users\xxx\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])

Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 5 other plugins)

System:

NodeJS : v8.12.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

app.component.ts:

export class MyApp {
  rootPage: any = HomePage;

  constructor(public platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public toastCtrl: ToastController, private firebase: Firebase) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();

      try {
        this.initializeFirebase();
      } catch (error) {
        this.firebase.logError(error);
      }

    });


  }

  initializeFirebase() {
    if (!this.platform.is("core")) {
      this.firebase.subscribe("all");
      this.platform.is('android') ? this.initializeFirebaseAndroid() : this.initializeFirebaseIOS();
    }
  }
  initializeFirebaseAndroid() {
    this.firebase.getToken().then(token => { });
    this.firebase.onTokenRefresh().subscribe(token => { })
    this.subscribeToPushNotifications();
  }
  initializeFirebaseIOS() {
    this.firebase.grantPermission()
      .then(() => {
        this.firebase.getToken().then(token => { });
        this.firebase.onTokenRefresh().subscribe(token => { })
        this.subscribeToPushNotifications();
      })
      .catch((error) => {
        this.firebase.logError(error);
      });
  }
  subscribeToPushNotifications() {
    this.firebase.onNotificationOpen().subscribe((response) => {
      if (response.tap) {
        console.log(response.body);
        //Received while app in background (this should be the callback when a system notification is tapped)
        //This is empty for our app since we just needed the notification to open the app
      } else {
        console.log(response.body);
        //received while app in foreground (show a toast)
        let toast = this.toastCtrl.create({
          message: response.body,
          duration: 3000
        });
        toast.present();
      }
    });
  }
}

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

import { Firebase } from '@ionic-native/firebase';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    Firebase
  ]
})
export class AppModule {}

Anyone having the same problem at the moment?

like image 778
fkuehne Avatar asked Oct 18 '18 12:10

fkuehne


1 Answers

try to check firebase cloud messaging plugin

ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated

perhaps double check google-services.json location

projects\src\app\google-services.json

and at the end re-add android and check plugins

ionic repair
like image 99
Nasenbaer Avatar answered Nov 09 '22 19:11

Nasenbaer