Search code examples
angularjscordovaionic-frameworkadmobintel-xdk

admobpro AdMob.showInterstitial() causes infinite loop


admobpro AdMob.showInterstitial() causes infinite loop

I am using admobpro in an ionic/angularjs app, and every time i call AdMob.showInterstitial() I get an advertisement to appear, but when i click the X to close the advertisement a new one instantly pops up. I was initally calling the showInterstitial from the init function but thought maybe this was the problem, so i created a test page that would show the interstitial when i clicked a button, the same result. infinite loop.

has anyone else had this problem.

   var admobid = {};
// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) { 
    admobid = { // for Android
        banner: 'ca-app-pub-6869992474017983/9375997553',
        interstitial: 'ca-app-pub-6869992474017983/1657046752'
    };
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
    admobid = { // for iOS
        banner: 'ca-app-pub-6869992474017983/4806197152',
        interstitial: 'ca-app-pub-6869992474017983/7563979554'
    };
} else {
    admobid = { // for Windows Phone
        banner: 'ca-app-pub-6869992474017983/8878394753',
        interstitial: 'ca-app-pub-6869992474017983/1355127956'
    };
}


function adSetter(){

if(window.AdMob) AdMob.createBanner( {
        isTesting:true,
    adId:admobid.banner, 
    position:AdMob.AD_POSITION.BOTTOM_CENTER, 
    autoShow:true} );

  if(window.AdMob) AdMob.prepareInterstitial( {adId:admobid.interstitial, autoShow:false} );

}
  function onDeviceReady(){
        adSetter();
  }


function domLoaded(){
 document.addEventListener("deviceready", onDeviceReady, false);
}

my code: fron ionic

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleLightContent();
    }

      //start admob

    domLoaded();

      //end admob
  });
})

Solution

  • i see you have mixed a bit of the code. the $ionicPlatform.ready() of ionic is called when the deviceready of cordova has occured so no need to call the device ready again inside the $ionicPlatform.ready()

    i have a complete demo for ionic ads here http://pointdeveloper.com/how-to-add-banner-ads-to-ionic-apps-using-admob-pro-plugin/

    From the code it seems ok and it should run the only thing that you have to make sure is that the AdMob.showInterstitial() is not being called in a loop.

    As you mentioned you also tried it with a button, i suggest you create a fresh project and try again.