I am at wits end. I cannot get this plugin to work. I have followed to the letter the instructions at PhoneGap Cordova Admob plugin not working (When you scroll down to the answer that references this plugin.) I an using the most recent phonegap cli running with phonegap serve. I even created an empty page (debug.html) to make sure no other code interfered.
What I have done so far:
I always get the alert that 'admob plugin not ready'.
I have tried changing the line "window.plugins.AdMob" to AdMob, plugins.Admob, navigator.Admob, window.Admob. I still get this error.
When I comment out that check ("if ( window.plugins && window.plugins.AdMob ) {"), and just force it to run the code, nothing happens. I get no errors on the command line, no errors anywhere that I can find to debug.
Here is my code:
<!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>
It is in main config.xml as
<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.
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.