在这个问题上的一些代码和想法就如何落实
见响应: https://stackoverflow.com/a/31187541/4025963
编辑
假设cordova-admob插件,基本的想法可能是这一个:
<a onclick="showInterstitial()" id="btn_prepare" class="pure-button pure-button-primary">GO TO APP</a>
而在你的js代码:
var isAppForeground = true;
var isShowMainOnCloseAd = false;
var isMainAlreadyShown = false;
var isInterstitialAvailable = false;
function showInterstitial() {
if (isInterstitialAvailable) {
admob.showInterstitialAd();
} else {
showMain(function() {
isMainAlreadyShown = true;
});
}
}
function initAds() {
if (admob) {
var adPublisherIds = {
ios : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
},
android : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
}
};
var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
admob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
autoShowInterstitial: false
});
registerAdEvents();
} else {
alert('cordova-admob plugin not ready');
}
}
function onAdLoaded(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialAvailable = true;
}
}
}
function onAdOpened(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL && !isMainAlreadyShown) {
isShowMainOnCloseAd = true;
}
}
function onAdClosed(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL && isShowMainOnCloseAd) {
isShowMainOnCloseAd = false;
if (!isMainAlreadyShown) {
showMain(function() {
isMainAlreadyShown = true;
});
}
}
}
function onPause() {
if (isAppForeground) {
isAppForeground = false;
}
}
function onResume() {
if (!isAppForeground) {
setTimeout(admob.requestInterstitialAd, 1);
isAppForeground = true;
}
}
function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdOpened, onAdOpened);
document.addEventListener(admob.events.onAdClosed, onAdClosed);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
initAds();
// request an interstitial
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);
此峰从谷歌介绍了什么是我想要的:https://storage.googleapis.com/support-kms-prod/91E0E29ADFA1A1BF42097E0699CC491BE874 –