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

Do not show ads after inserting ad ID #279

Open diegoestacho999 opened 5 years ago

diegoestacho999 commented 5 years ago

Guys, good afternoon, I need help. I'm using this plugin to integrate an Ionic3 application with Admob. I can perfectly display all ad templates in "TEST" mode. But when I add the ID of an ad I created in Admob, it does not display. It simply does not show any errors on the console. Just does not show, does anyone have any idea what I might be doing wrong?

My TS :

import { AdMobFree, AdMobFreeRewardVideoConfig, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig } from '@ionic-native/admob-free';

constructor(private adMobFree: AdMobFree, private platform: Platform) { this.video(); }

  async video(){
    try {
      const videoRewardsConfig: AdMobFreeRewardVideoConfig = {
        id: 'ca-app-pub-8000726989219599/1642316907',
        isTesting: true,
        autoShow: true
      }

      this.adMobFree.rewardVideo.config(videoRewardsConfig);

      const result = await this.adMobFree.rewardVideo.prepare();
      this.adMobFree.rewardVideo.show();
      console.log("VIDEO : " +result);
    }
    catch (e) {
      console.error(e);
    }
  }
diegoestacho999 commented 5 years ago

Test ads, I can display with no problem, but when I put any ad with ID, it shows me an OK in the console, but does not display.

If anyone can help please, I'm grateful.

diegoestacho999 commented 5 years ago

@ratson Could you give me a hand?

ugurozturk commented 5 years ago

Any news ?

diegoestacho999 commented 5 years ago

Hi, good morning, I have managed to solve this problem. Some code changes, I'll post the solution here later, thankful.

ultisoftmeta commented 5 years ago

Thanks for the update. I am facing the same issue. I will really appreciate any pointers to resolve this issue. Thanks again.

diegoestacho999 commented 5 years ago

To my surprise, I've been testing now and it's not working. Do you have any banner and video ids so I can test?

ultisoftmeta commented 5 years ago

I am trying banner ads. Code snippet is given below. I am replacing my ad unit id here and also marking isTesting to false .

var admobid = {} if (/(android)/i.test(navigator.userAgent)) { // for android & amazon-fireos admobid = { banner: 'ca-app-pub-3940256099942544/6300978111', } } else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios admobid = { banner: 'ca-app-pub-3940256099942544/2934735716', } }

document.addEventListener('deviceready', function() { admob.banner.config({ id: admobid.banner, isTesting: true, autoShow: true, }) admob.banner.prepare()

}, false)

diegoestacho999 commented 5 years ago

Good morning, I do not know if you have solved it, but here is my code:

`import { Injectable } from '@angular/core'; import { AdMobFree, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig, AdMobFreeRewardVideoConfig} from '@ionic-native/admob-free'; import { Events } from 'ionic-angular';

interface AdMobType { banner: string, interstitial: string, rewardvideo: string,

};

@Injectable() export class AnunciosProvider {

public ADbannerShow: boolean; public AdvideoShow: boolean;

constructor(private admob: AdMobFree, public events: Events,) { events.subscribe('ADSandroid', (b, i, v, t, s) => { this.initAds(b, i, v, t, s); }); }

initAds(b, i, v, t, s) { var admobid: AdMobType; if (/(android)/i.test(navigator.userAgent) && t == 'android') { admobid = { // for Android banner: b, interstitial: i, rewardvideo: v }; } else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { admobid = { // for iOS banner: 'ca-app-pub-8000726989219599/5437708216', interstitial: 'ca-app-pub-8000726989219599/2835881014', rewardvideo: 'ca-app-pub-8000726989219599/1642316907' }; } else { admobid = { // for Windows Phone banner: 'ca-app-pub-8000726989219599/5437708216', interstitial: 'ca-app-pub-8000726989219599/2835881014', rewardvideo: 'ca-app-pub-8000726989219599/1642316907' }; }

const bannerConfig: AdMobFreeBannerConfig = {
  id: admobid.banner,
  offsetTopBar: false,
 // autoShow: false
}

// if (i.trim() != '') { const bannerConfigI: AdMobFreeInterstitialConfig = { id: admobid.interstitial }

//}

  const bannerConfigV: AdMobFreeRewardVideoConfig = {
   // autoShow: false,
    id: admobid.rewardvideo
  }

this.admob.banner.config(bannerConfig); 
this.admob.interstitial.config(bannerConfigI);   
this.admob.rewardVideo.config(bannerConfigV);
this.ADbannerShow = s;

}

async showAdsB() { try { const result = await this.admob.banner.prepare(); console.log(result); this.admob.banner.show(); } catch (e) { console.error(e); } }

async showAdsI() { try { const result = await this.admob.interstitial.prepare(); console.log(result); this.admob.interstitial.show(); } catch (e) { console.error(e); } }

async showAdsV() { try { const result = await this.admob.rewardVideo.prepare(); console.log(result); this.admob.rewardVideo.show(); } catch (e) { console.error(e); } }

} ` That's an ads provider. "ionig g provider ads"

on your app.components, enter this code, and replace the ids for the ones you need. Being in the following sequence, banner, interstitial, reward video.

`import { Component } from '@angular/core'; import { Platform, Events } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home'; import { AnunciosProvider } from '../providers/anuncios/anuncios'; @Component({ templateUrl: 'app.html' }) export class MyApp { rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public GVP: AnunciosProvider, public events: Events ) { platform.ready().then(() => { this.events.publish('ADSandroid', 'ca-app-pub-8000726989219599/5437708216', 'ca-app-pub-8000726989219599/6213586887', 'ca-app-pub-8000726989219599/8700574455', 'android', true);

  if (this.GVP.ADbannerShow)
    this.GVP.showAdsB();

  statusBar.styleDefault();
  splashScreen.hide();
});

} }`

uokivan commented 4 years ago

Hi all

Do anyone fix it ? Thank you very much

By Ivan