Phonegap AdMob无法在iPhone上运行

时间:2018-03-08 18:52:57

标签: iphone cordova admob phonegap

我的问题是,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)。

0 个答案:

没有答案