//initialize the goodies
function initAd(){
if ( window.plugins && window.plugins.AdMob ) {
var ad_units = {
ios : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE
},
android : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //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: false, // receiving test ad
autoShow: false // 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
});
}
//display the banner
function showBannerFunc(){
window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
window.plugins.AdMob.showInterstitialAd();
}
3条答案
按热度按时间bq3bfh9z1#
你最好的选择是使用一个预先制作的插件。我有经验的一个很好地为我在iOS和Android上使用 cordova 6,如你所提到的。
完整指令在此处为https://github.com/sunnycupertino/cordova-plugin-admob-simple或https://www.npmjs.com/package/cordova-plugin-admob-simple
要安装:
如果您使用的是Eclipse,请将google-play-services.jar复制到libs文件夹中。
将以下行添加到清单文件中,刚好在结束应用程序标记之前
现在,在您的javascript中添加以下函数:
从onDeviceReady()调用初始化()
调用showInterstitialFunc()和showBannerFunc()来显示广告。
请记住,您必须等待一段时间才能显示间隙,因为它需要时间来加载。
希望这个有用。
zpgglvta2#
对我来说,这是最简单的方法:
https://www.npmjs.com/package/cordova-plugin-admobpro-firebase我已经在用了,iOS和Android都很好用...
感谢@ir2pid***“这个用户在没有说明的情况下可以获得30%的收入。"***所以它会拿走你的一些收入。
z5btuh9x3#
您可以使用以下插件:
Admob-plus
这似乎是目前最流行的软件包。它是cordova-plugin-admob-free插件的继承者。我目前正在研究它以供我使用。