cordova创建iOS项目
2016-03-09 15:45
387 查看
1.配置环境
1. cordova是利用nodeJS
b8cf
进行管理的, 首先下载nodeJS (http://nodejs.org)
2. 使用命令行安装
sudo npm install -g cordova
3. 创建工程
cordova create hello(文件夹名) com.example.hello(id) HelloWorld(工程名)
4.添加相关组件并运行
cd hello
cordova platform add ios
cordova build
2.写插件
iOS类, 放入目录Plugins下
3.Login.html文件加入工程
4.login,js文件加入工程
5.文件配置
config.xml中添加
6.使用
继承类
7.通讯
OC主动调JS
1. cordova是利用nodeJS
b8cf
进行管理的, 首先下载nodeJS (http://nodejs.org)
2. 使用命令行安装
sudo npm install -g cordova
3. 创建工程
cordova create hello(文件夹名) com.example.hello(id) HelloWorld(工程名)
4.添加相关组件并运行
cd hello
cordova platform add ios
cordova build
2.写插件
iOS类, 放入目录Plugins下
#import <Cordova/CDVPlugin.h> @interface Test2 : CDVPlugin - (void)test:(CDVInvokedUrlCommand*)command; @end
#import "Test2.h" @implementation Test2 -(void)test:(CDVInvokedUrlCommand *)command { CDVPluginResult * pluginResult = nil; NSString* echo = [command.arguments objectAtIndex:0]; if (echo != nil && [echo length] > 0) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"ios send OK"]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; } [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } @end
3.Login.html文件加入工程
路径: hello->platforms->ios->www下(工程中Staging下www)
4.login,js文件加入工程
路径: hello->platforms->ios->www->plugins->tansun-plugin-login->www下(路径不存在就新建)
5.文件配置
config.xml中添加
<feature name="Login"> <param name="ios-package" value="Test2" /> <param name="onload" value="true" /> </feature>
其中Login为自定义名字 Test2为插件类名 cordova_plugins.js中添加
{ "file": "plugins/tansun-plugin-login/www/login.js",//login.js路径 "id": "com.gldjc.guangcaiclient.login",//js文件定义的id "clobbers": [ "Login"//config.xml中自定义的名字 ] }
6.使用
继承类
#import <Cordova/CDVViewController.h> @interface MainViewController : CDVViewController
重写init方法 设置self.startPage = @"Login.html";
7.通讯
OC主动调JS
id <CDVWebViewEngineProtocol> engine = self.webViewEngine; if(engine) { [engine evaluateJavaScript:[NSString stringWithFormat:@"方法名('%@','%@')", self.name, self.password] completionHandler:^(id result, NSError *error) { NSLog(@"result == %@, error == %@", error); }]; }
JS通过cordova调OC
function mybtn(){ Login.loginSuccess(); //Login为自定义的名字 } loginSuccess:function() { exec(function(PluginResult){ alert(PluginResult); }, null, "Login", "test", ["AAAAA","BBBBB"]); }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- iOS推送的那些事
- IOS 改变键盘颜色代码