AdMob Cordova未在Cordova应用中展示广告横幅

时间:2018-05-15 10:13:55

标签: javascript android cordova admob

我是Cordova的新手,我想在我的Cordova应用程序中实现广告,我已经制作了它的演示版,但是当我运行我的应用程序时,我看不到横幅广告。 我已点击此链接:https://www.npmjs.com/package/cordova-plugin-admob-simple 我和这个链接做了同样的事情。我展示了我的代码:

function initAd(){
    if ( window.plugins && window.plugins.AdMob ) {
        var ad_units = {
            ios : {
                banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',
                interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'
            },
            android : {
                banner: 'ca-app-pub-901042ds533264/4645275146',
                interstitial: 'ca-app-pub-9010443dsd64/4610326568'
            }
        };
        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, LARGE_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();
    } else {
        alert('admob plugin not ready');
    }

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(){ });
}

function showBannerFunc(){
window.plugins.AdMob.createBannerView();}
function showInterstitialFunc(){
window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown and show when it's loaded.
window.plugins.AdMob.requestInterstitialAd();}

1 个答案:

答案 0 :(得分:0)

这是您的完整代码吗?因为我看不到你在哪里称这些功能。

如果您查看新创建的项目,请在www/js/index.js的文件中添加receivedEvent函数中对函数的调用。

请查看this example,但如果您直接复制粘贴,请确保将app.initialize();添加为最新行(如www/js/index.js文件中所示)。

此致 贝努瓦。