【问题标题】:Phonegap cordova-plugin-admob-simple Cannot Get Any Ads to ShowPhonegap cordova-plugin-admob-simple 无法显示任何广告
【发布时间】:2026-02-04 16:30:02
【问题描述】:

我束手无策。我无法让这个插件工作。我已按照PhoneGap Cordova Admob plugin not working 处的说明进行操作(当您向下滚动到引用此插件的答案时。)我正在使用与 phonegap serve 一起运行的最新 phonegap cli。我什至创建了一个空页面 (debug.html) 以确保没有其他代码受到干扰。

到目前为止我做了什么:

  • 确保插件存在于 main config.xml 中
  • 在网络浏览器中检查 Admob.js 文件实际上是从插件文件夹加载的。
  • 确保在platforms/android/android.json 中引用了该插件
  • 确保我在页面上链接了 cordova.js
  • 确保插件位于platforms/android/assets/www/plugins
  • 添加了平台android
  • 该插件显示在 phonegap 插件列表中
  • 安装插件和/或运行 phonegap serve 时没有错误
  • 用 isTesting 测试真假
  • 确保 deviceready 实际上正在触发
  • 检查并重新检查了我的 Admob 代码。

我总是收到“admob 插件未准备好”的警报。

我尝试将“window.plugins.AdMob”行更改为 AdMob、plugins.Admob、navigator.Admob、window.Admob。我仍然收到此错误。

当我注释掉该检查 ("if ( window.plugins && window.plugins.AdMob ) {") 并强制它运行代码时,什么也没有发生。我在命令行上没有收到任何错误,在我可以找到调试的任何地方都没有错误。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <meta name="msapplication-tap-highlight" content="no" />
    <title>Debug Page</title>
    <style>
        .bodyStyle{
            font-size: 32px;
        }
    </style>
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script> 

</head>
<body >
<script>
    function onDeviceReady() {
        console.log("DEVICE READY");
//initialize the goodies

        if ( window.plugins && window.plugins.AdMob ) {
            var ad_units = {
                ios : {
                    banner: 'ca-app-pub-1631005955280974/1599263468',       //PUT ADMOB ADCODE HERE
                    interstitial: 'ca-app-pub-1631005955280974/6029463060'  //PUT ADMOB ADCODE HERE
                },
                android : {
                    banner: 'ca-app-pub-1631005955280974/1599263468',       //PUT ADMOB ADCODE HERE
                    interstitial: 'ca-app-pub-1631005955280974/6029463060'  //PUT ADMOB ADCODE HERE
                }
            };
            var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;

            window.plugins.AdMob.setOptions( {
                publisherId: admobid.banner,
                interstitialAdId: admobid.interstitial,
                adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
                bannerAtTop: false, // set to true, to put banner at top
                overlap: true, // banner will 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
            });

            registerAdEvents();
            window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown
            window.plugins.AdMob.requestInterstitialAd();

        } else {
            alert( 'admob plugin not ready' );
        }

//functions to allow you to know when ads are shown, etc.
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(){
            window.plugins.AdMob.createInterstitialView();          //REMOVE THESE 2 LINES IF USING AUTOSHOW
            window.plugins.AdMob.requestInterstitialAd();           //get the next one ready only after the current one is closed
        });
    }
    function showBannerFunc(){
    AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
    AdMob.showInterstitialAd();
}

    document.addEventListener("deviceready", onDeviceReady, false);
</script>
<button type='button' onclick='showBannerFunc();'>SHOW BANNER</button>
<br/><br/>
<button type='button' onclick='showInterstitialFunc();'>SHOW INTER</button>
</body>
</html>

它在 main config.xml 中

<plugin name="cordova-plugin-admob-simple" spec="~3.3.3" />

拜托,我在这方面已经超过 2 周了,我已经用谷歌搜索了所有我能找到的东西。我必须阅读至少 100 页来寻求帮助,但不知道还能尝试什么。我所找到的一切,我都尝试过,但无济于事。甚至没有什么不同,它只是根本不显示任何类型的广告。横幅或其他。即使我点击按钮。请帮帮我。谢谢。

【问题讨论】:

    标签: plugins admob phonegap


    【解决方案1】:

    好吧,我终于想通了。我正在使用 Phonegap 服务。这不支持插件,或至少不支持 3rd 方插件。您必须使用 Phonegap 运行。

    【讨论】:

      【解决方案2】:

      我目前处于您 2 周前所处的阶段。我已经为 Admob 测试了不同的插件,但没有显示广告。 不幸的是,即使我正在生成一个 apk 文件并在移动设备上运行它,也没有任何反应。 我已经使用了您的代码,但按下“显示横幅”按钮时没有显示任何内容。

      我使用了虚拟 ID (ca-app-pub-3940256099942544/6300978111) 以及我自己的 ID。

      也许你可以看看我的问题并给出建议: Using AdMob and Cordova - ad is not displayed

      谢谢,

      彼得

      【讨论】:

        最近更新 更多