Cordova-plugin-firebasex: IONIC 3 - FIREBASE - onNotificationOpen()

Created on 19 Jul 2019  路  10Comments  路  Source: dpa99c/cordova-plugin-firebasex

IONIC 3 - Push Notifications Firebase

Hello,

A week ago I was able to push, click on the message and get the data correctly. A few days ago, trying to run the project on another machine showed error that the repository could not be found. It was like this:

https://stackoverflow.com/questions/56014935/problem-with-play-services-measurement-base-on-ionic

In the item,

2 - Install: ionic cordova plugin add https://github.com/dpa99c/cordova-plugin-firebase#GH-1057-April-05-android-build-issue

I noticed you are now using the "cordova-plugin-firebasex". So far so good, I installed and the push came correctly.

But now I can not make any dealings when I click on the notification. I used it like this:

app.component.ts

this.platform.ready().then(() => {
      statusBar.backgroundColorByHexString("#00516d");
      splashScreen.hide();

      this.fcm
        .listenToNotifications()
        .pipe(
          tap(msg => {
            console.log(msg);
          })
        )
        .subscribe();
});

fcm.ts

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

constructor (public firebase: Firebase) {}

listenToNotifications() {
    return this.firebase.onNotificationOpen();
}

From what I've noticed, the new plugin can not execute the onNotificationOpen()

Can you tell me where I'm going wrong?

Sorry for English errors!
My sincerest regards.

ionic

Most helpful comment

As you'll see from the CHANGELOG, this fork has deviated from cordova-plugin-firebase such that cordova-plugin-firebasex is no longer the same plugin as cordova-plugin-firebase - it has a different API and behaviour, e.g. onNotificationOpen() renamed to onMessageReceived()

The @ionic-native/firebase wrapper points at cordova-plugin-firebase so if you want to use this fork, you'll need to use it directly via the JS API rather than via the Ionic Native Typescript wrapper for cordova-plugin-firebase.

All 10 comments

As you'll see from the CHANGELOG, this fork has deviated from cordova-plugin-firebase such that cordova-plugin-firebasex is no longer the same plugin as cordova-plugin-firebase - it has a different API and behaviour, e.g. onNotificationOpen() renamed to onMessageReceived()

The @ionic-native/firebase wrapper points at cordova-plugin-firebase so if you want to use this fork, you'll need to use it directly via the JS API rather than via the Ionic Native Typescript wrapper for cordova-plugin-firebase.

@dpa99c Does downgrading cordova-plugin-firebasex to version 4.0.0 resolve onNotificationOpen problem?

@Abdulrahmanh95 v4.0.0 is out-of-date with respect to the version which contains numerous bug fixes and additional features. I would not recommend using 4.0.0 for this reason.

@dpa99c Thanks a lot.
I've just fix it with version 6 is working properly with my ionic 3 application.

@Abdulrahmanh95,
I am using ionic 3 and added this plugin as well. And i am struck without import firebase how to use the methods? can i get some sample script. Thanks Benny

before:
this.firebase.onNotificationOpen();
after:
(this.firebase as any).onMessageReceived();

@benskarunya
You just have to use without firebase service (using plain JavaScript):

(<any>window).FirebasePlugin.onNotificationOpen(function (response) {
    if (response.tap) { console.log('push to some page'); }
 })

and you can receive the token the same way:

(<any>window).FirebasePlugin.getToken(function (token) { console.log('token', token); })

I feel you, we can have this transform as onNotificationOpen:
.ts onNotificationOpen() { return new Observable(observer => { (window as any).FirebasePlugin.onMessageReceived((response) => { observer.next(response); }); }); }

I'm getting Cannot read property 'setScreenName' of undefined

if I do ionic cordova run android
and set a breakpoint, FirebasePlugin is undefined..
(window as any).FirebasePlugin

anyone have any idea..?

my bad make sure you use cordova android >8

Was this page helpful?
0 / 5 - 0 ratings