[英]AdMob Cordova not showing Ads banner in Cordova app
我是Cordova的新手,我想在自己的Cordova應用程序中實現Ads,已經進行了演示,但是運行應用程序時看不到橫幅。 我點擊了此鏈接: 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();}
這是您的完整代碼嗎? 因為我看不到您在哪里調用這些函數。
如果你看一下你的新創建的項目,在該文件中www/js/index.js
你應該在一個呼叫添加到您的功能receivedEvent
功能。
看一下此示例 ,但是如果直接復制粘貼,請確保添加app.initialize();
作為最新行(如www/js/index.js
文件中)。
問候,Benoit。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.