I'm moving some of our older Phonegap 3 apps into build.phonegap.com and rebuilding with Phonegap 4. Impressed so far, but this next app has AdMob which was previously set up in the Java files directly, so I'm trying to rework...
As far as I can tell, the best mechanism for this is the cordova-admobpro plugin, so I've added:
<plugin name="cordova-plugin-admobpro"/>
to the config.xml . I've then added a new JS tag after /body as per the documentation (also tried inside the body but after the cordova.js tag, and inside the head with the defer attribute):
<script type="text/javascript" src="js/admob.js"></script>
Finally, I've built admob.js as per the various examples:
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-1111111111111111-1111111111',
interstitial: 'ca-app-pub-1111111111111111/1111111111'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-1111111111111111-1111111111',
interstitial: 'ca-app-pub-1111111111111111/1111111111'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-1111111111111111-1111111111',
interstitial: 'ca-app-pub-1111111111111111/1111111111'
};
}
function initApp() {
if(AdMob) {
// this will create a banner on startup
AdMob.createBanner( {
adId: admobid.banner,
position: AdMob.AD_POSITION.BOTTOM_CENTER,
overlap: false,
offsetTopBar: false,
bgColor: 'black'
} );
// this will load a full screen ad on startup
AdMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: true
});
}
}
if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}
(Obviously the banner ID's are real in the actual app)
This isn't working though. When compiled and installed to a device, I'm seeing neither the startup ad or the banner ad. Testing in a browser and code inspecting is useless since AdMob isn't going to exist until the plugin references in config.xml is compiled in.
Am I missing something blindingly obvious?