【问题标题】:Ionic 2 video ad pluginIonic 2 视频广告插件
【发布时间】:2017-07-03 07:12:03
【问题描述】:

我正在尝试为 ionic2 寻找一些好的广告展示(视频)插件。我已经尝试使用https://github.com/cranberrygame/cordova-plugin-ad-adcolony,但我无法调整它以使用 ionic2 和 angular2。我还查看了 AdMob ,它是 ionic2 插件,但不支持视频广告,因为我读过(仅横幅)。你能告诉我我应该使用什么以及如何使用我的 ionic2 应用程序。谢谢。

顺便说一句,当我尝试使用下面的 HTML 以 window.plugins.adcolony.showIntersitialAd() 这种方式运行 adcolony 时

<button ion-button (click)="window.plugins.adcolony.showInterstitialAd();">showInterstitialAd</button>

返回

HomePage.html:15 ERROR TypeError: Cannot read property 'plugins' of undefined

当我尝试像这样运行它时

<button ion-button (click)="window.adcolony.showInterstitialAd();">showInterstitialAd</button>

它返回以下错误:

HomePage.html:15 ERROR TypeError: Cannot read property 'adcolony' of undefined

任何帮助将不胜感激,谢谢:)

顺便说一句,我正在通过https://apps.ionic.io/apps测试应用程序

【问题讨论】:

    标签: javascript cordova ionic-framework ionic2 admob


    【解决方案1】:

    试试这个插件:https://github.com/appfeel/admob-google-cordova

    cordova plugin add cordova-admob
    

    请注意,您必须等待插页式广告加载,并且在您的应用处于后台时禁用插页式加载也是一个好主意,因为在您请求插页式广告的那一刻和您展示它的那一刻之间存在延迟:

    <button ion-button (click)="tryToShowInterstitial();">showInterstitialAd</button>
    

    在你的 javascript 代码中:

    var isAppForeground = true;
    var isInterstitialAvailable = false;
    
    function tryToShowInterstitial() {
        if (isInterstitialAvailable) {
            admob.showInterstitialAd();
        } else {
            // Do your button action here when there are no ads to show
        }
    }
    
    function onAdLoaded(e) {
      if (isAppForeground) {
        if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
          isInterstitialAvailable = true;
        }
      }
    }
    
    function onAdClosed(e) {
      if (isAppForeground) {
        if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
          // Would you like to prepare next interstitial?
          setTimeout(admob.requestInterstitialAd, 1);
          isInterstitialAvailable = false;
        }
      }
    }
    
    function onPause() {
      if (isAppForeground) {
        admob.destroyBannerView();
        isAppForeground = false;
      }
    }
    
    function onResume() {
      if (!isAppForeground) {
        setTimeout(admob.createBannerView, 1);
        setTimeout(admob.requestInterstitialAd, 1);
        isAppForeground = true;
      }
    }
    
    // optional, in case respond to events
    function registerAdEvents() {
      document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
      document.addEventListener(admob.events.onAdClosed, onAdClosed);
    
      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();
    
      // display a banner at startup
      admob.createBannerView();
    
      // request an interstitial
      admob.requestInterstitialAd();
    }
    
    document.addEventListener("deviceready", onDeviceReady, false);
    

    【讨论】:

    • 嗨大卫,谢谢你的回答。我已经在我的项目中集成了 AdMob,我正在使用rewardvideo,但问题是,有时奖励视频广告无法加载:(有时工作完美,但有时无法加载,你有什么建议为什么会发生这种情况吗?: (
    猜你喜欢
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多