Phonegap Desktop App external plugins

你离开我真会死。 提交于 2019-12-05 06:48:53

I'm the author of the plugin you are trying to use. It seems you are using the command line interface which it doesn't have any automatization on <gap:plugin ...> yet (and I'm not sure that it's comming in the near future).

As Sanfor says, if you are using Phonegap CLI, you should add every plugin manually:

phonegap local plugin add cordova-admob

Or if you are using Cordova:

cordova plugin add cordova-admob

If you are using Phonegap Build, you should put the tag in config.xml:

<gap:plugin name="cordova-admob" source="npm" />

In that case, you can also follow the instructions at https://github.com/appfeel/admob-phonegap-build-demo.git to test the demo app in your Phonegap Build account.

Remember to always use admob after deviceready event has been fired:

function onAdLoaded(e) {
  if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
    admob.showInterstitialAd();
  }
}

function onDeviceReady() {
  document.removeEventListener('deviceready', onDeviceReady, false);

  // Set AdMobAds options:
  admob.setOptions({
    publisherId:          "YOUR_PUBLISHER_ID",                  // Required
    interstitialAdId:     "YOUR_PUBLISHER_OR_INTERSTITIAL_ID",  // Optional
  });

  // Start showing banners inmediately:
  admob.createBannerView();

  // To show an interstitial, call admob.showInterstitialAd() when onAdLoaded is fired:
  document.addEventListener(admob.events.onAdLoaded, onAdLoaded, false);
  admob.requestInterstitial();

  // You could also request and show an interstitial like this:
  // admob.requestInterstitialAd({ autoShowInterstitial: true});
}

document.addEventListener('deviceready', onDeviceReady, false);

It's interesting to know if you are testing with CLI to later use PGB. However, I'm not sure if it helps a mock-up of the admob functionality. Let me know if it's your case. The only situation that comes to my mind is that you would like to test the app in a desktop browser, where plugins aren't supported. But even in that case I would suggest you to use ripple incubator from github (or even weinre, but if you are in a mac it's better to use safari developer tools).

EDIT 2016-04-22

Updated old plugin references to newest ones and npm source for phonegap build.

I'm not an expert, but I haven't got that to work. I think you are indeed mixing PG and PGB configurations (gap:plugin). Since I haven't had luck with getting those work (I suppose you would need to add those via CLI), I can only suggest what I've done: mock those plugins that doesn't exist by default. You can for example define admob object with the necessary functions available for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!