最新バージョン(6)を使用してCordovaにマルチプラットフォームアプリを作成していますが、iOSとAndroidでAdMob広告を使用する際に問題が発生しています。 AdMobのコードサンプルをダウンロードしましたが、javascriptからそのサンプルを制御すると、私はプラグインのアーキテクチャについて何かを理解していますが、それを動作させるようには思えません。AndroidとiOSの両方でAdMob広告をCordovaプロジェクトに統合するにはどうすればよいですか?
助けてください。
最新バージョン(6)を使用してCordovaにマルチプラットフォームアプリを作成していますが、iOSとAndroidでAdMob広告を使用する際に問題が発生しています。 AdMobのコードサンプルをダウンロードしましたが、javascriptからそのサンプルを制御すると、私はプラグインのアーキテクチャについて何かを理解していますが、それを動作させるようには思えません。AndroidとiOSの両方でAdMob広告をCordovaプロジェクトに統合するにはどうすればよいですか?
助けてください。
これにはプレマイドプラグインを使用することをお勧めします。あなたが言及したように、私はiOSとAndroidの両方でCordova 6を使ってうまく動作するものを経験しました。
完全な手順は、インストールするには、ここでhttps://github.com/sunnycupertino/cordova-plugin-admob-simpleまたはここhttps://www.npmjs.com/package/cordova-plugin-admob-simple
です:
cd yourappfolder
cordova plugin add cordova-plugin-admob-simple
Eclipseを使用している場合、LIBSフォルダにグーグル・プレイservices.jarにコピーします。
は、マニフェストファイルに次の行を追加します。あなたのJavaScriptで今ちょうど終わるアプリケーションタグの前に
<meta-data android:name="com.google.android.gms.version" android:value="8487000" />
、以下の機能を追加します。onDeviceReadyから
//initialize the goodies
function initAd(){
if (window.plugins && window.plugins.AdMob) {
var ad_units = {
ios : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE
},
android : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE
}
};
var admobid = (/(android)/i.test(navigator.userAgent)) ? ad_units.android : ad_units.ios;
window.plugins.AdMob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER, //use SMART_BANNER, BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
bannerAtTop: false, // set to true, to put banner at top
overlap: true, // banner will overlap webview
offsetTopBar: false, // set to true to avoid ios7 status bar overlap
isTesting: false, // receiving test ad
autoShow: false // auto show interstitial ad when loaded
});
registerAdEvents();
window.plugins.AdMob.createInterstitialView(); //get the interstitials ready to be shown
window.plugins.AdMob.requestInterstitialAd();
} else {
//alert('admob plugin not ready');
}
}
//functions to allow you to know when ads are shown, etc.
function registerAdEvents() {
document.addEventListener('onReceiveAd', function(){});
document.addEventListener('onFailedToReceiveAd', function(data){});
document.addEventListener('onPresentAd', function(){});
document.addEventListener('onDismissAd', function(){ });
document.addEventListener('onLeaveToAd', function(){ });
document.addEventListener('onReceiveInterstitialAd', function(){ });
document.addEventListener('onPresentInterstitialAd', function(){ });
document.addEventListener('onDismissInterstitialAd', function(){
window.plugins.AdMob.createInterstitialView(); //REMOVE THESE 2 LINES IF USING AUTOSHOW
window.plugins.AdMob.requestInterstitialAd(); //get the next one ready only after the current one is closed
});
}
//display the banner
function showBannerFunc(){
window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
window.plugins.AdMob.showInterstitialAd();
}
コールのinit()( )
showInterstitialFunc()およびshowBannerFunc()を呼び出して広告を表示します。
読み込みに時間がかかるため、インタースティシャルを表示する前に少し待たなければならないことに注意してください。
これが役に立ちます。
ありがとうございました。 –
このプラグインでポイントを獲得できないようにユーザーがビデオをクローズするかどうかを制御する機会はありますか? – proofzy