【发布时间】:2018-11-12 23:59:08
【问题描述】:
我应该把setInterval(showInterstitialAd, 120000);放在哪里?我想使用下面的代码使用 admob 在我的 phonegap 应用上每 2 分钟创建一次插页式广告。我使用以下插件:<gap:plugin name="phonegap-admob" source="npm"/>
var isPendingInterstitial = false;
var isAutoshowInterstitial = false;
function prepareInterstitialAd() {
if (!isPendingInterstitial) {
admob.requestInterstitialAd({
autoShowInterstitial: isAutoshowInterstitial
});
}
}
function onAdLoadedEvent(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL && !isAutoshowInterstitial) {
isPendingInterstitial = true;
}
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
admob.setOptions({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",
});
document.addEventListener(admob.events.onAdLoaded, onAdLoadedEvent);
prepareIntestitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);
function showInterstitialAd() {
if (isPendingInterstitial) {
admob.showInterstitialAd(function () {
isPendingInterstitial = false;
isAutoshowInterstitial = false;
prepareInterstitialAd();
});
} else {
// The interstitial is not prepared, so in this case, we want to show the interstitial as soon as possible
isAutoshowInterstitial = true;
admob.requestInterstitialAd({
autoShowInterstitial: isAutoshowInterstitial
});
}
}
【问题讨论】:
标签: javascript android cordova admob