2017-06-07 2 views
0

setInterval(showInterstitialAd, 120000);はどこに置くべきですか? admobを使用して、私のphonegapアプリで2分ごとにインタースティシャル広告を作成するために、以下のコードを使用したいと思います。 「;いくつかの詳細を追加してくださいあなたのポストは、ほとんどのコードであるように見えます。」、ので... <gap:plugin name="phonegap-admob" source="npm"/>PhonegapのAdMob修正

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 
     }); 
    } 
} 

:私は、次のプラグインを使用します

答えて

0

Googleは「インタースティシャルが予期せず開始する」と考えられるため、インタースティシャルを一度表示することはお勧めしません(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); 
    } 
    } 
}