2016-12-01 16 views
0

インタースティシャルアドインを含む単純なHTMLページを作成することはできません。私はプログラミングでは新しく、このコードで何が間違っているのか分かりません。私はphonegapでアプリをやっています。 config.xmlに<gap:plugin name="com.admob.plugin" version="3.0.0" source="plugins.cordova.io" />も追加しました。助けてください。それは私が既に持っているものです:(ハイフンの代わりにドットで)新しいプラグインの仕様をインタースティシャル広告は表示されません

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 


<script type="text/javascript" src="cordova.js"></script> 
<script type="text/javascript"> 
function showInterstitial(){ 
    admob.isInterstitialReady(function(isReady){ 
     if(isReady){ 
      admob.showInterstitial(); 
     }else{ 
      alert("need cached before show"); 
     } 
    }); 
} 
function onInterstitialReceive (message) { 
    alert("onMInterstitialReceive ,you can show it now"); 
} 
function onReceiveFail (message) { 
    var msg=admob.Error[message.data]; 
    if(msg==undefined){ 
     msg=message.data; 
    } 
    alert("load fail: "+message.type+" "+msg); 
} 
function onDeviceReady() { 
    admob.initAdmob("ca-app-pub-5461976332457981/1789654352","ca-app-pub-5461976332457981/7220849555"); 
    document.addEventListener(admob.Event.onInterstitialReceive, onInterstitialReceive, false); 
    document.addEventListener(admob.Event.onInterstitialFailedReceive,onReceiveFail, false); 
} 

document.addEventListener('deviceready',onDeviceReady, false); 
</script> 
</body> 
</html> 

答えて

0

を使用します。

<gap:plugin name="phonegap-admob" source="npm"/> 

次に、あなたのコードは次のようにする必要があります(あなたもどのようにここでは例を見ることができます2分ごとにインタースティシャルを自動再生する:https://github.com/appfeel/admob-google-cordova/wiki/setOptions):

var isAppForeground = true; 
var isInterstitialAvailable = false; 

function onAdLoaded(e) { 
    if (isAppForeground && e.adType === admob.AD_TYPE.INTERSTITIAL) { 
    isInterstitialAvailable = true; 
    } 
} 

function onAdOpened(e) { 
    if (isAppForeground && e.adType === admob.AD_TYPE.INTERSTITIAL) { 
    isInterstitialAvailable = false; 
    admob.requestInterstitialAd(); // Request next interstitial 
    } 
} 

function onPause() { 
    if (isAppForeground) { 
    admob.destroyBannerView(); 
    isAppForeground = false; 
    isInterstitialAvailable = false; 
    } 
} 

function onResume() { 
    if (!isAppForeground) { 
    setTimeout(admob.createBannerView, 1); 
    setTimeout(admob.requestInterstitialAd, 1); 
    isAppForeground = true; 
    } 
} 

function registerAdEvents() { 
    document.addEventListener(admob.events.onAdLoaded, onAdLoaded); 
    document.addEventListener(admob.events.onAdOpened, onAdOpened); 

    document.addEventListener("pause", onPause, false); 
    document.addEventListener("resume", onResume, false); 
} 

function initAds() { 
    var ids = { 
    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)) ? ids.android : ids.ios; 

    admob.setOptions({ 
    publisherId:   admobid.banner, 
    interstitialAdId:  admobid.interstitial, 
    autoShowInterstitial: false, 
    isTesting:   true // False on production apps 
    }); 

    registerAdEvents(); 
} 

function onDeviceReady() { 
    document.removeEventListener('deviceready', onDeviceReady, false); 

    if (window.admob) { 
    initAds(); 
    admob.createBannerView(); // display a banner at startup 
    admob.requestInterstitialAd(); // cache an interstitial 
    } else { 
    alert('Admob plugin not ready'); 
    } 
} 

document.addEventListener("deviceready", onDeviceReady, false); 

function showInterstitial() { 
    if (isInterstitialAvailable) { 
    admob.showInterstitialAd(); 
    } else { 
    console.log('Interstitial is not yet available'); 
    } 
} 
関連する問題