Phonegap AdMob在iPhone上不起作用

问题描述 投票:0回答:1

我的问题是admob插件在PhoneGap IOS测试应用程序上不起作用(这是插件:https://github.com/appfeel/admob-google-cordova

var isAppForeground = true;

function initAds() {
  if (!admob) {
    var adPublisherIds = {
      ios : {
        banner : "ca-app-pub-3940256099942544/2934735716",
        interstitial : "ca-app-pub-3940256099942544/4411468910"
      },
      android : {
        banner : "ca-app-pub-3940256099942544/6300978111",
        interstitial : "ca-app-pub-3940256099942544/1033173712"
      }
    };

    var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;

    admob.setOptions({
      publisherId:      admobid.banner,
      interstitialAdId: admobid.interstitial,
      //tappxIdiOS:       "/XXXXXXXXX/Pub-XXXX-iOS-IIII",
      //tappxIdAndroid:   "/XXXXXXXXX/Pub-XXXX-Android-AAAA",
      //tappxShare:       0.5,

    });

    registerAdEvents();


  } else {
    alert('admobAds plugin not ready');
  }
}

function onAdLoaded(e) {
  if (isAppForeground) {
    if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
      console.log("An interstitial has been loaded and autoshown. If you want to load the interstitial first and show it later, set 'autoShowInterstitial: false' in admob.setOptions() and call 'admob.showInterstitialAd();' here");
    } else if (e.adType === admob.AD_TYPE_BANNER) {
      console.log("New banner received");
    }
  }
}

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

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

// optional, in case respond to events
function registerAdEvents() {
  document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
  document.addEventListener(admob.events.onAdFailedToLoad, function (e) {});
  document.addEventListener(admob.events.onAdOpened, function (e) {});
  document.addEventListener(admob.events.onAdClosed, function (e) {});
  document.addEventListener(admob.events.onAdLeftApplication, function (e) {});
  document.addEventListener(admob.events.onInAppPurchaseRequested, function (e) {});

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

该插件已成功安装,我将这3行放在onDeviceReady下:

initAds();
admob.createBannerView();
admob.requestInterstitialAd();

以上各行之后,同一功能(onDeviceReady)中的所有内容均未执行(该功能崩溃)。>>

同样,我使用PhoneGap应用进行测试(来自AppStore)。>>

[我的问题是admob插件无法在PhoneGap IOS测试应用程序上运行(这是插件:https://github.com/appfeel/admob-google-cordova)var isAppForeground = true;函数initAds(){...

iphone cordova admob phonegap
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.