用于离子ios的Admob插件

时间:2017-01-30 16:12:34

标签: ios cordova ionic-framework

我正在与android和ios这两个平台合作,我必须在我的项目中实施横幅广告。我尝试过各种插件来实现横幅广告。 我已经尝试了android和ios的以下链接,它与android运行良好,但添加此插件后我的应用程序显示错误,

https://www.codeproject.com/Articles/1005149/Adding-AdMob-to-Ionic-Framework-Application-Step-B

插件名称 - cordova-plugin-admob

添加插件后,我使用了命令' ionic build ios',它返回 - 命令的错误代码65:xcodebuild with args:-xcconfig, 不知道这个问题的确切原因。

1 个答案:

答案 0 :(得分:0)

Atlast我找到了在离子应用中加载广告的解决方案,

请添加插件 cordova插件添加cordova-plugin-admobpro

在html页面中添加以下代码, //用于加载jquery1.9.js-

的脚本标记
<script type="text/javascript" src="jquery-1.9.js"></script>

<script>
  var admobid = {};
  if( /(android)/i.test(navigator.userAgent) ) {
   admobid = { // for Android
   banner: 'ca-app-pub-6869992474017983/9375997553',
   interstitial: 'ca-app-pub-6869992474017983/1657046752'
  };} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
  banner: 'ca-app-pub-6869992474017983/4806197152',
  interstitial: 'ca-app-pub-6869992474017983/7563979554'
};} else {
admobid = { // for Windows Phone
  banner: 'ca-app-pub-6869992474017983/8878394753',
  interstitial: 'ca-app-pub-6869992474017983/1355127956'
};}function createSelectedBanner(){
  //alert("banner");
if(AdMob) AdMob.createBanner({
  adId: admobid.banner,
  overlap: $('#overlap').is(':checked'),
  offsetTopBar: $('#offsetTopBar').is(':checked'),
  adSize: 'BANNER',
  position: AdMob.AD_POSITION.BOTTOM_CENTER,
});}function showBannerAtPosition(){
if(AdMob) AdMob.showBanner( $('#adPosition').val() );}function onDeviceReady() {
if (! AdMob) { 
    //alert( 'admob plugin not ready' ); 
    return; 
}

initAd();

// display a banner at startup
createSelectedBanner();}function initAd(){//alert("init");
AdMob.getAdSettings(function(info){
  console.log('adId: ' + info.adId + '\n' + 'adTrackingEnabled: ' + info.adTrackingEnabled);}, function(){
  console.log('failed to get user ad settings');
});

AdMob.setOptions({
  adSize: 'BANNER',
  position: AdMob.AD_POSITION.BOTTOM_CENTER,
  isTesting: true, // set to true, to receiving test ad for testing purpose
  bgColor: 'black', // color name, or '#RRGGBB'
  // autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
  // offsetTopBar: false, // avoid overlapped by status bar, for iOS7+
});

// new events, with variable to differentiate: adNetwork, adType, adEvent
$(document).on('onAdFailLoad', function(e){
  // when jquery used, it will hijack the event, so we have to get data from original event
  if(typeof e.originalEvent !== 'undefined') e = e.originalEvent;
  var data = e.detail || e.data || e;

  //alert('error: ' + data.error +', reason: ' + data.reason +', adNetwork:' + data.adNetwork +', adType:' + data.adType +', adEvent:' + data.adEvent); // adType: 'banner', 'interstitial', etc.
});
$(document).on('onAdLoaded', function(e){
});
$(document).on('onAdPresent', function(e){
});
$(document).on('onAdLeaveApp', function(e){
});
$(document).on('onAdDismiss', function(e){
});

$('#btn_create').click(createSelectedBanner);
$('#btn_remove').click(function(){
  AdMob.removeBanner();
});

$('#btn_show').click(showBannerAtPosition);
$('#btn_hide').click(function(){
  AdMob.hideBanner();
});

// test interstitial ad
$('#btn_prepare').click(function(){
  AdMob.prepareInterstitial({
    adId:admobid.interstitial,
    autoShow: $('#autoshow').is(':checked'),
  });
});

$('#btn_showfull').click(function(){
  AdMob.showInterstitial();
});

// test case for #256, https://github.com/floatinghotpot/cordova-admob-pro/issues/256
$(document).on('backbutton', function(){
  if(window.confirm('Are you sure to quit?')) navigator.app.exitApp();
});$(document).ready(function()
    {
        //alert("start");
        // on mobile device, we must wait the 'deviceready' event fired by cordova
        if(/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent)) {
          document.addEventListener('deviceready', onDeviceReady, false);
        } else {
          onDeviceReady();
        }

    });

</script>