我们可以针对特定DIV展示adMob广告吗?

时间:2016-03-15 04:41:44

标签: ionic-framework admob

我们可以在Android应用中显示特定DIV的adMob广告吗? 如果可能的话,你能告诉我如何实施吗?

1 个答案:

答案 0 :(得分:-3)

安装此插件 cordova插件添加https://github.com/floatinghotpot/cordova-plugin-admob.git

以及控制器内的过去波纹管代码

$(function () {
    // alert('1');
    if ((/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent))) {
      document.addEventListener('deviceready', initApp, false);
    } else {
      initApp()
      // alert('2');
    }
  })

  function initApp() {
    // alert('3');
    initAd()
    // display the banner at startup
    window.plugins.AdMob.createBannerView();
  }

  function initAd() {
    // alert('4');
    if (window.plugins && window.plugins.AdMob) {
      var ad_units = {
        ios: {
          banner: 'ca-app-pub-6869992474017983/4806197152',
          interstitial: 'ca-app-pub-6869992474017983/7563979554'
        },
        android: {
          banner: 'ca-app-pub-6869992474017983/9375997553',
          interstitial: 'ca-app-pub-6869992474017983/1657046752'
        },
        wp8: {
          banner: 'ca-app-pub-6869992474017983/8878394753',
          interstitial: 'ca-app-pub-6869992474017983/1355127956'
        }
      };
      var admobid = "";
      if (/(android)/i.test(navigator.userAgent)) {
        admobid = ad_units.android;
      } else if (/(iphone|ipad)/i.test(navigator.userAgent)) {
        admobid = ad_units.ios;
      } else {
        admobid = ad_units.wp8;
      }
      window.plugins.AdMob.setOptions({
        publisherId: admobid.banner,
        interstitialAdId: admobid.interstitial,
        bannerAtTop: false, // set to true, to put banner at top
        overlap: false, // set to true, to allow banner overlap webview
        offsetTopBar: false, // set to true to avoid ios7 status bar overlap
        isTesting: true, // receiving test ad
        autoShow: true // auto show interstitial ad when loaded
      });
      // alert('5');
      registerAdEvents()

    } else {
      // alert( 'admob plugin not ready' );
    }
  }
  // optional, in case respond to events

  function registerAdEvents() {
    document.addEventListener('onReceiveAd', function() {});
    document.addEventListener('onFailedToReceiveAd', function(data) {});
    document.addEventListener('onPresentAd', function() {});
    document.addEventListener('onDismissAd', function() {});
    document.addEventListener('onLeaveToAd', function() {});
    document.addEventListener('onReceiveInterstitialAd', function() {});
    document.addEventListener('onPresentInterstitialAd', function() {});
    document.addEventListener('onDismissInterstitialAd', function() {});
    // alert('6');
  }

  function onResize() {
    // alert('7');
    var msg = 'web view: ' + window.innerWidth + ' x ' + window.innerHeight;
    document.getElementById('sizeinfo').innerHTML = msg;
  }
  // ADMob
})