命令详解: http://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html#The%20Command-Line%20Interface
一些部署和配置参考: http://panyongzheng.iteye.com/blog/2157846
Cordova 3.x 基础(8) -- 几个不可或缺的lib http://rensanning.iteye.com/blog/2021720
中文引导: http://inching.org/2014/06/04/cordova-tutorial/
Cordova 3.x 基础(1) -- 环境搭建(Windows / Android) http://rensanning.iteye.com/blog/2016364
关于meta viewport中target-densitydpi属性 http://blog.csdn.net/fengri5566/article/details/9414599
phonegap在android中如何退出程序 http://blog.sina.com.cn/s/blog_6d3fcc7e0101ddmz.html
官方插件:
1. cordova plugin add org.apache.cordova.dialogs 用于实现alret,confim等方法
2. cordova plugin add org.apache.cordova.console 实现输出调试信息
3. cordova plugin add org.apache.cordova.inappbrowser 使用内置浏览器打开连接
4. cordova plugin add com.phonegap.plugins.barcodescanner 条形码 https://build.phonegap.com/plugins/261
5. PhonegapOCRPlugin iOS 扫描插件
5. cordova plugin add https://github.com/albertarvesu/image-scanner-cordova-plugin.git 扫描插件
Local Storage API methods.
localStorage.getItem(): Returns the value associated with the key.
localStorage.setItem(): Saves the specified key-value pair.
localStorage.removeItem(): Removes the item associated with the key argument.
localStorage.clear(): Removes all items saved in localStorage.
安装和创建例子
1. sudo yum -y install npm
2. sudo npm install -g cordova
3. cordova create hello com.example.hello HelloWorld
4. cordova platform add android
5. cordova platform rm android //删除某个平台的代码
6. cordova build //编译,
A: cordova build ios
B: cordova prepare ios
cordova compile ios
7. cordova emulate android 或者 cordova run --emulator android //运行到svd
8. cordova android 或者 cordova run android //运行到手机
9. ordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git 或者 cordova plugin add org.apache.cordova.dialogs //增加插件,到工程根目录执行
PhoneGap/Cordova3.0+ 使用,以及添加插件笔记 http://blog.csdn.net/u012146107/article/details/12852895
添加org.apache.cordova.dialogs插件例子:用于实现alret,confim等方法。,祥解: http://plugins.cordova.io/#/package/org.apache.cordova.dialogs
1. cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git //增加插件,到工程根目录执行
2. 在index.js的app对象里面加入
alertDismissed: function () { // do something }, showAlert: function () { navigator.notification.alert( 'You are the winner!', // message app.alertDismissed, // callback 'Game Over', // title 'Done' // buttonName ); }
3. 在index.html加入
<p><a href="#" onclick="app.showAlert();return false;">点链接</a></p>
ajax技术,注意包含编辑头部信息。
服务器:cakephp代码
public function callAjax() { $a=$this->request->header('username');//获得头部信息 $dlist = array( "rows" => array("11", "22", "33","11", "22", "33","11", "22", "33"), "status" => 1); return new CakeResponse(array('body' => json_encode($dlist), 'status' => 200)); }
客户端:
$("#ajax_test").on("tap",function(){ $.ajax({ url: "http://192.168.0.198/Demos/callAjax", data: [], type: 'POST', dataType: 'json', headers: { "username":"[email protected]"//传入头部信息,比如验证信息等。 }, success: function (data, textStatus) { navigator.notification.alert( '成功='+ $.toJSON(data), // message app.alertDismissed, // callback '远程调用', // title '确定' // buttonName ); }, error: function (xhr, textStatus, errorThrown) { navigator.notification.alert( '失败='+xhr, // message app.alertDismissed, // callback '远程调用', // title '确定' // buttonName ); } }); });
应用图标
http://cordova.apache.org/docs/en/edge/config_ref_images.md.html#Icons%20and%20Splash%20Screens
<icon src="res/icon.png" platform="android" width="57" height="57" density="mdpi" />
调试方式:
1. GapDebug, 不支持Linux
2. Mock 模式调试技术, Phonegap-desktop 项目, 一直没更新。
3. 代理模式调试技术weinre, Weinre 无法实现 JavaScript 动态调试
Weinre: http://blog.csdn.net/niuer09/article/details/8795321
sudo npm -g install weinre
weinre --boundHost 192.168.0.198 --httpPort 8081 --all
/usr/lib/node_modules/weinre/web/target/target-script-min.js加入工程
问题:
1. ANDROID_HOME is not set and "android" command not in your PATH,
明明环境变量都弄好了,执行android也能打开了,为什么还报错?