简体   繁体   English

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

[英]AdMob Cordova not showing Ads banner in Cordova app

I'm new in Cordova, I want to implement Ads in my Cordova application, I have made its demo, but I cannot see banner when I run my app. 我是Cordova的新手,我想在自己的Cordova应用程序中实现Ads,已经进行了演示,但是运行应用程序时看不到横幅。 I have follow this link : https://www.npmjs.com/package/cordova-plugin-admob-simple i have done same as this link. 我点击了此链接: https : //www.npmjs.com/package/cordova-plugin-admob-simple我已经完成了与此链接相同的操作。 i showing my code : 我显示我的代码:

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

Is this your full code ? 这是您的完整代码吗? because I cannot see where you call those functions. 因为我看不到您在哪里调用这些函数。

If you have a look at your fresh created project, in the file in www/js/index.js you should add a call to your functions in the receivedEvent function. 如果你看一下你的新创建的项目,在该文件中www/js/index.js你应该在一个呼叫添加到您的功能receivedEvent功能。

Have a look here on this example , but if you copy paste it directly, ensure to add app.initialize(); 看一下此示例 ,但是如果直接复制粘贴,请确保添加app.initialize(); as the latest line (like in the www/js/index.js file). 作为最新行(如www/js/index.js文件中)。

Regards, Benoit. 问候,Benoit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM