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

Ionic 2/3 issue with Interstitial #118

Closed erperejildo closed 5 years ago

erperejildo commented 6 years ago

Can't display this ad on my app.

According with Ionic documentation this is the correct way:

this.admobFree.interstitial.prepare()
        .then(() => {    
            this.admobFree.interstitial.show()
        })
        .catch(e => console.log(e));

But I get this error:

Uncaught (in promise): Interstital not ready yet

So I tried this:

this.admobFree.interstitial.prepare()
        .then(() => {
          var that = this;
          setTimeout(function(){
            that.admobFree.interstitial.show()
          },2000)
        })
        .catch(e => console.log(e));

... and works!

I also tried your way (https://ratson.github.io/cordova-plugin-admob-free/variable/index.html#static-variable-interstitial) but doesn't work either:

this.admobFree.interstitial.prepare();
this.admobFree.interstitial.show();

Uncaught (in promise): cordova_not_available

No sure if the problem here is either the way of Ionic manages these promises or this library

patrickboulay commented 6 years ago

Same problem for me on Android

ratson commented 6 years ago

show() should be called after admob.interstitial.events.LOAD event after prepare().

@erperejildo Did you solve this? Maybe you could put up the answer here.

patrickboulay commented 6 years ago

Not sure to understand about the events.LOAD.

I call the interstitial like this:

            this.admobFree.interstitial.prepare()
            .then(()=> {
                this.admobFree.interstitial.show();
            })
            .catch( e => { 
                console.log("Show Interstitial error: " + JSON.stringify(e));
            });

Is not correct?

JimJty commented 6 years ago

@patrickboulay, this isn't in the docs, but there are some examples:

https://github.com/ratson/cordova-plugin-admob-free/blob/master/examples/basic/www/js/index.js

Basically you need to listen for events from the admob directly (if you set autoShow to false in the config). Here is your code rewritten (partially), to listen for the admob load event:

import {HostListener} from '@angular/core';

...

@HostListener('document:admob.interstitial.events.LOAD', ['$event'])
onAdInterstitialLoaded(ev) {
  this.admobFree.interstitial.show().catch( e => { 
       console.log("Show Interstitial error: " + JSON.stringify(e));
     });
}

...

    this.admobFree.interstitial.prepare()
    .catch( e => { 
       console.log("Prepare Interstitial error: " + JSON.stringify(e));
     });
erperejildo commented 6 years ago

No @ratson, I didn't solve it yet but only because I'd need to fix the other bug first before this one

Shadowstep33 commented 6 years ago

@erperejildo @ratson

this is somewhat of note:


const bannerConfig: AdMobFreeBannerConfig = {
        isTesting: true,
        autoShow: true
      };
      this.admobFree.interstitial.config(bannerConfig);

      let insterst = this.admobFree.interstitial.prepare()
      .then( (interst) => {
      });```

Always works, where as if I add the 'id' property to the config it never works.
erperejildo commented 6 years ago

I'll give it a try as soon as I can. Thanks @Shadowstep33

Shadowstep33 commented 6 years ago

So, this is actually working for me:

      const bannerConfig: AdMobFreeBannerConfig = {
        id: 'xxx',
        autoShow: true
      };
      this.admobFree.interstitial.config(bannerConfig);

      let insterst = this.admobFree.interstitial.prepare()
      .then( (interst) => {
      });

I had to go to my admob account and I had to make sure to set up the payment details and then wait a bit (I waited overnight). You'll see a red banner on your admob dashboard saying to set up payment details.

erperejildo commented 6 years ago

I think that's the minimum and basic configuration. I tried that already but it might be different now with latest version, it's been a while. I'm also trying with the pro version and also getting issues. This drives me mad...

erperejildo commented 6 years ago

I think that's the minimum and basic configuration. I tried that already but it might be different now with latest version, it's been a while. I'm also trying with the pro version and also getting issues. This drives me mad...

I wouldn't mind to pay for this, srl

hamdanihamza commented 5 years ago

you can always use the setTimeout() function

erperejildo commented 5 years ago

Solution: https://github.com/ratson/cordova-plugin-admob-free/issues/119#issuecomment-390397862

ahayder commented 5 years ago

In my case autoShow: true worked for me. Remember when autoShow is true you don't need to call the interstitial.show() function. Hope it works. Cheers!!!