【问题标题】:admob interstitial ad issue?admob 插页式广告问题?
【发布时间】:2016-09-02 08:03:28
【问题描述】:

我正在使用cordova phonegap android 平台开发应用程序。

我在我的应用中安装了用户广告插件,一切正常,但在设备 moto G 中,即使在我离开我的应用后,插页式广告也会打开。

如果你们中的任何人遇到此问题并已解决,请告诉我。

任何帮助将不胜感激。

【问题讨论】:

    标签: android cordova phonegap-plugins cordova-admob


    【解决方案1】:

    请在此处查看文档(我刚刚更新了它):https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd

    注意:即使安卓应用在 背景。出于这个原因,建议停止横幅和 当 onPause 和 onResume 事件发生时,插页式广告和重新加载 被检测到。

    因此,您应该监听onPauseonResume 事件:

    var isAppForeground = true;
    
    function onAdLoaded(e) {
      if (isAppForeground) {
        if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
          admob.showInterstitialAd();
        }
      }
    }
    
    function onPause() {
      if (isAppForeground) {
        admob.destroyBannerView();
        isAppForeground = false;
      }
    }
    
    function onResume() {
      if (!isAppForeground) {
        setTimeout(admob.requestInterstitialAd, 1);
        isAppForeground = true;
      }
    }
    
    // optional, in case respond to events
    function registerAdEvents() {
      document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
    
      document.addEventListener("pause", onPause, false);
      document.addEventListener("resume", onResume, false);
    }
    
    function initAds() {
      if (admob) {
        var adPublisherIds = {
          ios : {
            banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
            interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
          },
          android : {
            banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
            interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
          }
        };
    
        var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
    
        admob.setOptions({
          publisherId:          admobid.banner,
          interstitialAdId:     admobid.interstitial,
          autoShowInterstitial: false
        });
    
        registerAdEvents();
    
      } else {
        alert('AdMobAds plugin not ready');
      }
    }
    
    function onDeviceReady() {
      document.removeEventListener('deviceready', onDeviceReady, false);
      initAds();
    
      // request an interstitial
      admob.requestInterstitialAd();
    }
    
    document.addEventListener("deviceready", onDeviceReady, false);
    

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多