Phonegap Desktop外部插件 [英] Phonegap Desktop App external plugins

查看:210
本文介绍了Phonegap Desktop外部插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有运气添加外部插件到Phonegap桌面应用程序?我已经成功添加核心插件像设备,但不是外部。我试图添加com.admob.google到我的项目,我不能让admob被识别为一个命令。
在config.xml我添加:

Has anyone had luck adding external plugins to the Phonegap Desktop App? I have had success adding core plugins like "Device" but not external ones. I am trying to add com.admob.google to my project and I can not get admob to be recognized as a command. In the config.xml I add:

<gap:plugin name="com.admob.google" source="plugins.cordova.io" />

在我的.js文件中的deviceReady函数中,我有:

And in my deviceReady function in my .js file I have:

try{
    admob.requestInterstitialAd(); //or any other admob command
}
catch(err){
    alert("admob not loaded");
}



每次在我的设备(通过Phonegap开发者应用程序)

Every time on my device (via Phonegap Developer App) I get the alert saying that "admob not loaded".

我可以混合Phonegap和Phonegap Build命令吗?

Am I mixing Phonegap and Phonegap Build commands?

桌面应用不支持自动包含外部插件?

Does the Phonegap Build Desktop App not support auto-inclusion of external plugins yet?

推荐答案

我是您要使用的插件的作者。似乎你使用的命令行界面它没有任何自动化在< gap:plugin ...> (但我不确定它是在不久的将来)。

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).

Sanfor说,如果您使用 Phonegap CLI ,您应该手动添加每个插件:

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

phonegap local plugin add cordova-admob

或如果您使用 Cordova

cordova plugin add cordova-admob

如果您使用 Phonegap Build ,您应该将标签放在 config.xml

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

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

在这种情况下,您也可以按照 https://github.com/appfeel/admob-phonegap-build-demo.git 来测试演示应用程序

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.

请记住在 deviceready 活动被触发后始终使用admob:

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);

这很有趣,知道你是否使用CLI测试以后使用PGB。然而,我不知道它是否有助于模拟的admob功能。让我知道如果是你的情况。我想到的唯一情况是,您想在桌面浏览器中测试应用程序,不支持插件。但即使在这种情况下,我建议您使用 github的波纹孵化器(或甚至weinre,但是

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

将旧插件引用更新为最新版本,并将npm源更新为phonegap build。

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

这篇关于Phonegap Desktop外部插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆