You might have encountered an error like, when requesting an ad from AdMob using Cordova AdMob Plugin: interstitialAd is null, call createInterstitialView first
Chances are you are doing it wrong. To create an Interstitial Ad you need to take of three things:
- Use interstitialAdId as the key to pass you ad unit id in your options object
- First create a Interstitial view using createInterstitialView
- In success callback from createInterstitialView use requestInterstitialAd to request an ad
if (window.plugins && window.plugins.AdMob) {
var admob_key = device.platform == "Android" ? "XXXXX" : "YYYYYYYYY";
var admob = window.plugins.AdMob;
var options = {
interstitialAdId: admob_key,
autoShow: true
};
admob.createInterstitialView(options, function() {
admob.requestInterstitialAd({
'isTesting': false
},
function() {
admob.showAd(true);
},
function(error) {
console.log('failed to request ad ' + error);
}
);
},
function() {
console.log('failed to create Interstitial view');
});
} else {
console.log("Admob plugin not available");
}
Thank you so much you save my work of 1 week....thank you again
ReplyDelete