0

我束手无策。我无法让这个插件工作。我已按照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>

它在主 config.xml 中

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

Please, I have been at this for over 2 weeks, I have googled and searched all I could. I must've read at least 100 pages looking for help and do not know what else to try. Everything I have found, I have tried to no avail. Nothing different even happens, it just simply doesn't show ads of any kind. Banner or otherwise. Even when I click the buttons. Help me please. Thank you.

4

2 回答 2

0

Ok I finally figured it out. I was using Phonegap Serve. This does NOT support plugins, or at least 3rd party plugins. You have to use Phonegap run.

于 2017-05-10T01:22:32.123 回答
0

I'm currently at the stage where you have been 2 weeks ago. I have tested already different plugins for Admob but no ad is displayed. Unfortunately even when I'm generating a apk file and run it on a mobile device nothing happens. I have used your code but nothing is shown when pressing the "show Banner" button.

I have used the dummy ID (ca-app-pub-3940256099942544/6300978111) as well as my own ID.

Maybe you can take a look at my problem and give an advice: Using AdMob and Cordova - ad is not displayed

Thanks,

Peter

于 2017-05-23T20:05:17.247 回答