Phonegap构建如何将插件添加到应用程序 [英] Phonegap build how do you add plugins to app
问题描述
文档说:
要在您的项目中包含一个插件,需要两个步骤:
"There are two steps to including a plugin in your project:
使用config.xml导入本机代码
Importing the native code using the config.xml
引用该插件的JavaScript代码"
http://docs.build.phonegap.com/zh_CN/configuring_plugins.md.html#importing-native
要进行引用,请在html文件中执行此操作:
And to reference you do this in your html file:
<script src="cordova.js"></script>
<script src="barcodescanner.js"></script> <-this
但是,您如何知道要替换条形码扫描器.js的内容.
However, how do you know what to put in place of barcodescanner.js.
实际上,如果我仅使用 phonegap build 来构建和测试我的应用程序,而不使用任何本地应用程序,那么我不知道包含插件的工作流程.我尝试使用cli包含插件.但这并没有更新根config.xml
.因此,我手动将代码config.xml放入 https://build.phonegap.com/plugins /1163 .但是在此页面上没有提及要包含在javascript文件中的内容.我是否使用acceleration.js,device-motion.js
In fact i don't know about work flow of including plugins if i am using solely using phonegap build to build and test my app and not use anything local. I tried including plugin using cli. But that didn't update root config.xml
. So i manually put the code config.xml, as can be found https://build.phonegap.com/plugins/1163 . But on this page there was no mentioning of what to include in javascript file. do i use acceleration.js, device-motion.js
推荐答案
如果您希望将条码扫描器包含在phonegap版本中,则可以执行以下操作,
if you want to include the bar code scanner with phonegap build you coulde do the following,
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.example"
versionCode = "10"
version = "1.0.0" >
<!-- versionCode is optional and Android only -->
<name>PhoneGap Example</name>
<description>
An example for phonegap build docs.
</description>
<author href="https://build.phonegap.com" email="support@phonegap.com">
Hardeep Shoker
</author>
<!-- We'll include the Barcode plugin as an example -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
<gap:plugin name="org.apache.cordova.camera"/>
<gap:plugin name="org.apache.cordova.device-motion"/>
<gap:plugin name="org.apache.cordova.device-orientation"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>
<gap:plugin name="org.apache.cordova.geolocation"/>
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.vibration"/>
</widget>
这是一个示例config.xml文件,包含在与您的主页相同的目录中.在javascript文件中,您不包含任何用于插件的脚本(请确保
This is an example config.xml file to include in the same directory as your homepage. In the javascript file you don't include any scripts for plugins(make sure
<script src="cordova.js"></script>
包括
).只需调用插件方法,构建将为您处理其余部分.例如,我在上面包括了振动插件.如果我想让手机振动,只需调用这样的功能,
is included). Just call the plugin methods and build will handle the rest for you.For example I have included the vibration plugin above. If I wanted my phone to vibrate I would simply call a function like this,
function test(){
navigator.notification.vibrate(1000);
}
不需要类似的东西,
<script src="barcodescanner.js"></script>
只需确保在config.xml文件中引用了插件,并且一切正常即可
Just make sure the plugin is referenced in the config.xml file and everything should be ok
这篇关于Phonegap构建如何将插件添加到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!