ratson / cordova-plugin-admob-free

New development has been moved to "admob-plus-cordova", https://github.com/admob-plus/admob-plus/tree/master/packages/cordova
https://github.com/admob-plus/admob-plus
MIT License
499 stars 214 forks source link

How to reset event listeners for INTERSTITIAL_CLOSE after closing an Ionic 3/Admob Free interstitial? #426

Open antoniocorreia opened 4 years ago

antoniocorreia commented 4 years ago

I'm having a problem after configured the Interstitial with this plugin.

First, I was able to display the Interstitial with the following config

let interConfig: AdMobFreeInterstitialConfig = {
        isTesting: false,
        autoShow: true,
        id: this.adconfig.idIntersticial,
      };

this.admob.interstitial.config(interConfig);

this.admob.interstitial
        .prepare()
        .then(() => {
          console.log('insterstitial displayed');
        })
        .catch((e) => console.log(e));

I'm calling this code twice in my Home.ts, and for each call I setup a listener to execute a specific action when the user closes the interstitial

 this.admob.on(this.admob.events.INTERSTITIAL_CLOSE).subscribe(() => {
       this.function1();
      });

and in another method

 this.admob.on(this.admob.events.INTERSTITIAL_CLOSE).subscribe(() => {
       this.function2();
      });

My problem is... the first time I close the interstitial everything works nicely, let's say I closed and the this.function1() method was called for the first scenario, but from the second call on the listeners are appended to the INTERSTITIAL_CLOSE, for example, if I execute the second scenario to close and execute this.function2() the this.function1()is called again after executing this.function2().

What am I doing wrong? And how can I reset the listeners?