如何 install/use cordova 插件?
How to install/use cordova plugins?
我已经安装了 cordova 5.3.3,我为 android 创建了我的应用程序:
cordova create Project
cd Project
cordova platform add android
在那之后,我压缩我的文件:
cd ..
zip -r Project.zip Project
并将其上传到 phonegap build 中:
https://build.phonegap.com/apps
在那里创建 apk 并将其安装到我的 android 之后,应用程序似乎工作正常,除非我尝试使用插件。
插件功能总是失败,而 javascript 代码的其余部分工作正常。
我添加的插件如下:
cordova plugin add org.apache.cordova.vibration
cordova platform rm android
cordova platform add android
如果我列出我的插件:
cordova plugin ls
我得到:
cordova-plugin-whitelist 1.0.0 "Whitelist"
org.apache.cordova.vibration 0.3.13 "Vibration"
我在使用 phonegap(版本 5.3.6)或仅上传仅包含 "www" 文件夹和 "config.xml" 文件的 zip 文件时遇到相同的行为。
我还在 Whosebug 中阅读了这些类似的问题:
phonegap plugins 5.1.1 cli don't work
Cordova plugins not working
但他们似乎对我的情况没有帮助。
index.html代码:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Teste Vibra</h1>
<button type="button" id="vibrar">Vibrar</button>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
</script>
</body>
javascript代码:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$(function(){
$( "#vibrar" ).click(function() {
navigator.vibrate(3000);
alert("abc");
});
})
}
我正在使用 JQuery 库 2.1.4.
好的。你有一个根本性的问题。不知何故,您没有阅读正确的文档。
请阅读本文以帮助您入门
阅读 粗体 点,然后阅读适用的每个部分的正文。
Top Mistakes by Developers new to Cordova/Phonegap
在这种情况下,您犯了错误 #1,
我引用:
1. Thinking Phonegap is just one system
There are three similar platforms, Cordova (CLI), Phonegap (CLI), and
Phonegag Build and five system (counting Cordova/Phonegap SDK1).
People often confuse the three very similar platforms and get tangled
in the minor variations that differentiate them.
Oddly enough, the best explanation comes from something built on top
of Angular, and wraps the Cordova/Phonegap CLI. - Ionic.
From the Ionic Blog The Last Word on Cordova and PhoneGap
PhoneGap proper was created around 2009 by a startup called Nitobi as an open source way to access the "native" environment through an embedded Web View in a native app. The goal of the project was to make it possible to build the bulk of a mobile app experience with pure web technologies like HTML5, CSS, and Javascript, but still be able to call into native code when necessary.
In 2011 Adobe purchased Nitobi and with it the rights to the PhoneGap brand, and the open source core was donated to the Apache Software Foundation under the name Cordova.
Read more on the Ionic Blog
已由 JesseMonroy650 指出,我认为 phonegap 和 phonegap 构建在同一系统中。但是插件的安装方式不同
示例:
- 电话间隙:
phonegap 插件添加 cordova-plugin-bluetooth-serial --save
- phonegap 构建:
将行“<gap:plugin name="cordova-plugin-bluetooth-serial" source="npm" />
”添加到 config.xml
要安装和使用 Cordova 插件,您需要按照以下步骤(安装简单的相机插件):
添加:
第 1 步:
cordova 插件添加 cordova-plugin-camera
例如,如果您想将此插件安装到离子框架项目中:
您应该按照以下命令编写:
ionic cordova 插件添加 cordova-plugin-camera
删除:
要删除插件,请使用以下命令
常用:
cordova 插件删除 cordova-plugin-camera
我已经安装了 cordova 5.3.3,我为 android 创建了我的应用程序:
cordova create Project
cd Project
cordova platform add android
在那之后,我压缩我的文件:
cd ..
zip -r Project.zip Project
并将其上传到 phonegap build 中:
https://build.phonegap.com/apps
在那里创建 apk 并将其安装到我的 android 之后,应用程序似乎工作正常,除非我尝试使用插件。
插件功能总是失败,而 javascript 代码的其余部分工作正常。
我添加的插件如下:
cordova plugin add org.apache.cordova.vibration
cordova platform rm android
cordova platform add android
如果我列出我的插件:
cordova plugin ls
我得到:
cordova-plugin-whitelist 1.0.0 "Whitelist"
org.apache.cordova.vibration 0.3.13 "Vibration"
我在使用 phonegap(版本 5.3.6)或仅上传仅包含 "www" 文件夹和 "config.xml" 文件的 zip 文件时遇到相同的行为。
我还在 Whosebug 中阅读了这些类似的问题:
phonegap plugins 5.1.1 cli don't work
Cordova plugins not working
但他们似乎对我的情况没有帮助。
index.html代码:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Teste Vibra</h1>
<button type="button" id="vibrar">Vibrar</button>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
</script>
</body>
javascript代码:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$(function(){
$( "#vibrar" ).click(function() {
navigator.vibrate(3000);
alert("abc");
});
})
}
我正在使用 JQuery 库 2.1.4.
好的。你有一个根本性的问题。不知何故,您没有阅读正确的文档。
请阅读本文以帮助您入门
阅读 粗体 点,然后阅读适用的每个部分的正文。
Top Mistakes by Developers new to Cordova/Phonegap
在这种情况下,您犯了错误 #1,
我引用:
1. Thinking Phonegap is just one system
There are three similar platforms, Cordova (CLI), Phonegap (CLI), and Phonegag Build and five system (counting Cordova/Phonegap SDK1). People often confuse the three very similar platforms and get tangled in the minor variations that differentiate them.
Oddly enough, the best explanation comes from something built on top of Angular, and wraps the Cordova/Phonegap CLI. - Ionic.
From the Ionic Blog The Last Word on Cordova and PhoneGap
PhoneGap proper was created around 2009 by a startup called Nitobi as an open source way to access the "native" environment through an embedded Web View in a native app. The goal of the project was to make it possible to build the bulk of a mobile app experience with pure web technologies like HTML5, CSS, and Javascript, but still be able to call into native code when necessary.
In 2011 Adobe purchased Nitobi and with it the rights to the PhoneGap brand, and the open source core was donated to the Apache Software Foundation under the name Cordova.
Read more on the Ionic Blog
已由 JesseMonroy650 指出,我认为 phonegap 和 phonegap 构建在同一系统中。但是插件的安装方式不同
示例:
- 电话间隙:
phonegap 插件添加 cordova-plugin-bluetooth-serial --save - phonegap 构建:
将行“<gap:plugin name="cordova-plugin-bluetooth-serial" source="npm" />
”添加到 config.xml
要安装和使用 Cordova 插件,您需要按照以下步骤(安装简单的相机插件):
添加:
第 1 步: cordova 插件添加 cordova-plugin-camera
例如,如果您想将此插件安装到离子框架项目中:
您应该按照以下命令编写:
ionic cordova 插件添加 cordova-plugin-camera
删除:
要删除插件,请使用以下命令
常用: cordova 插件删除 cordova-plugin-camera