Admob修复Phonegap

时间:2017-06-07 18:54:44

标签: javascript android cordova admob

有什么建议我应该把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
        });
    }
}

1 个答案:

答案 0 :(得分:0)

建议不要每隔一段时间显示一次插页式广告,因为Google可能会认为它是&#34;插页式广告意外推出&#34; (见https://support.google.com/admob/answer/6201362)。建议您显示与用户操作相关的插页式广告(即登录后,游戏开始或结束时等)

那就是说,你应该把它放在onAdClosed上。请参阅此处有关如何将其集成的完整示例:https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd

function onAdClosed(e) {
  if (isAppForeground) {
    if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
      setTimeout(admob.requestInterstitialAd, 1000 * 60 * 2);
    }
  }
}