【问题标题】:How do I show ads in Phonegap Build using the Phonegap-admob plugin?如何使用 Phonegap-admob 插件在 Phonegap Build 中展示广告?
【发布时间】:2020-09-18 03:20:45
【问题描述】:

我一直在尝试使用 Phonegap Build 制作一个使用 HTML、CSS 和 JS 的应用,但 admob 广告不会显示。我展示广告的 JS 代码是:

<script src="code.js"></script>
        <script type="text/javascript">
            function onDeviceReady() {
      document.removeEventListener('deviceready', onDeviceReady, false);

      // Set AdMobAds options:
      admob.setOptions({
        publisherId:           "ca-app-pub-3940256099942544/6300978111",  // Required
        interstitialAdId:      "ca-app-pub-3940256099942544/1033173712",  // Optional
        autoShowBanner:        true,                                      // Optional
        autoShowRInterstitial: false,                                     // Optional
      });

      // Start showing banners (atomatic when autoShowBanner is set to true)
      admob.createBannerView();

      // Request interstitial ad (will present automatically when autoShowInterstitial is set to true)
    function showad(){
         admob.requestInterstitialAd();
    }

    }
    document.addEventListener("deviceready", onDeviceReady, false);
        </script>

我的 config.xml 文件中还有 Phonegap Build 插件以及对 gap 标签的支持,但是当其他一切正常时,广告就不会显示。请帮忙。

【问题讨论】:

    标签: phonegap-plugins phonegap-build phonegap-admob


    【解决方案1】:

    这里是phonegap-admob插件的作者。

    您的config.xml 应如下所示:

    <gap:plugin name="phonegap-admob" source="npm"/>
    

    通常需要几天的时间才能开始看到广告。有些事情你可以验证:

    • admob.setOptions 上看到一个错字:autoShowRInterstitial --> autoShowInterstitial('R' 不正确)
    • publisherId 在最新版本中已弃用,请改用 bannerAdId(尽管它应该可以正常工作)
    • 您是否尝试过测试广告?它显示了什么? (https://admob-phonegap.com/set-options#baseoptions)
          admob.setOptions({
            bannerAdId:            "ca-app-pub-3940256099942544/6300978111",  // Required
            interstitialAdId:      "ca-app-pub-3940256099942544/1033173712",  // Optional
            autoShowBanner:        true,                                      // Optional
            autoShowInterstitial:  false,                                     // Optional
            isTesting:             true,                                      // Optional
          });
    

    你可以在https://admob-phonegap.com找到完整的文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多