2016-03-28 14 views
1

En son sürümü (6) kullanarak Cordova'da bir çoklu platform uygulaması yazıyorum ve AdMob reklamlarının iOS ve Android'de çalışmasını sağlamaya çalışırken çok fazla sorun yaşıyorum. AdMob için kod örneklerini indirdim, ancak javascript'ten kontrol etmek beni güldürüyor. Eklenti mimarisi hakkında bir şey anlıyorum, ama işe yaramayacak gibi görünmüyorum.AdMob reklamlarını hem Android hem de iOS için Cordova Projesi'ne nasıl entegre edebilirsiniz?

Lütfen

Yardım edin.

cevap

2

En iyi bahsiniz, bunun için önceden hazırlanmış bir eklenti kullanmaktır. IOS ve Android'de bana sözünü ettiğin gibi Cordova 6'yı kullanarak iyi çalışan biriyle ilgili deneyimim var.

Tam talimatlar https://github.com/sunnycupertino/cordova-plugin-admob-simple veya burada https://www.npmjs.com/package/cordova-plugin-admob-simple

yüklemek için buraya şunlardır: Eğer libs klasörüne google-play-services.jar kopyalamak, Eclipse kullanıyorsanız

cd yourappfolder 

cordova plugin add cordova-plugin-admob-simple 

. (OnDeviceReady dan

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

Çağrı init():

aşağıdaki işlevler ekleyin javascript

<meta-data android:name="com.google.android.gms.version" android:value="8487000" /> 

Şimdi sadece biten uygulama etiketinden önce, bildirim dosyasına aşağıdaki satırı ekleyin

Reklamları göstermek için showInterstitialFunc() ve showBannerFunc() öğesini çağırın.

Yüklemenin zaman alacağı için geçiş reklamını göstermeden önce biraz beklemeniz gerektiğini unutmayın.

Bu yardımcı olur umarım.

+0

Çok teşekkür ederim. –

+0

Kullanıcı, bu eklenti ile "puan" kazanmasını önlemek için yakın ödül videosunun kontrol edilip edilmediğini kontrol etme şansı var mı? – proofzy

İlgili konular