iOS原生项目嵌入Cordova
来源:互联网 发布:骚男辣条淘宝店网址 编辑:程序博客网 时间:2024/05/22 11:54
MAC OS High Sierra系统版本10.13
Xcode版本Version 9.0.1 (9A1004)
对于iOS原生项目嵌入cordova的一些记录,废话不说,开始正题!
嵌入cordova,网上一顿搜,搜到的都很详细,但是运行出问题,自己总结后记录下来,方便以后查阅,开始上手正式操作一遍。
首先需要创建一个cordova工程,cordova中文网,上面有很详细的教程,网址http://cordova.axuer.com/docs/zh-cn/latest/guide/cli/index.html
如何集成Cordova组件以WebView形式集成到Native应用中去,从头到尾顺序如下:
1.新建Demo工程,加入我们已经存在名为Demo项目,目录结构如下:
2、打开你创建好的cordova工程,拷贝CordovaLib、www文件夹和confil.xml到Demo文件夹下
如果CordovaLib文件夹下有build文件夹删除掉,那是编译cordova工程时自动创建的,目录结构如下:
3、将CordovaLib.xcodeproje添加到demo工程中,右键选择Add Files To Demo
4、添加www文件夹到demo工程中,这里注意勾选Create folder references
5、选择工程的Build Settings->Other Links, 设置-Objc -all_load
6.选择Build Phases->New Run Script Phase,将新增New Run Script Phase命名为copy www directory
7.Build Phases->Target Dependencies添加CordovaLib
8.Link Binary With Librarys添加libCordova.a, MobileCoreServices,AssetsLibrary
9、command + B 编译通过后创建视图控制器CordovaViewController,
这是.h与.m内容
#import <Cordova/CDVViewController.h>#import <Cordova/CDVCommandDelegateImpl.h>#import <Cordova/CDVCommandQueue.h>@interface CordovaViewController : CDVViewController@end@interface CordovaCommandDelegate : CDVCommandDelegateImpl@end@interface CordovaCommandQueue : CDVCommandQueue@end
#import "CordovaViewController.h"@implementation CordovaViewController- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Uncomment to override the CDVCommandDelegateImpl used // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self]; // Uncomment to override the CDVCommandQueue used // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self]; } return self;}- (id)init{ self = [super init]; if (self) { // Uncomment to override the CDVCommandDelegateImpl used // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self]; // Uncomment to override the CDVCommandQueue used // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self]; } return self;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];}#pragma mark View lifecycle- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated];}- (void)viewDidLoad{ [super viewDidLoad];}- (void)viewDidUnload{ [super viewDidUnload];}#pragma mark UIWebDelegate implementation//- (void)webViewDidFinishLoad:(UIWebView*)theWebView//{// theWebView.backgroundColor = [UIColor blackColor];//// return [super webViewDidFinishLoad:theWebView];//}@end@implementation CordovaCommandDelegate#pragma mark CDVCommandDelegate implementation- (id)getCommandInstance:(NSString*)className{ return [super getCommandInstance:className];}- (NSString*)pathForResource:(NSString*)resourcepath{ return [super pathForResource:resourcepath];}@end@implementation CordovaCommandQueue- (BOOL)execute:(CDVInvokedUrlCommand*)command{ return [super execute:command];}@end10、然后是APPdelegate.m里面设置,不然还是跳转到ViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. CordovaViewController *cord = [[CordovaViewController alloc]init]; self.window.rootViewController = cord; [self.window makeKeyWindow]; return YES;}
11、运行工程,就会出现出图所示
至此嵌入cordova就结束了
- iOS原生项目嵌入Cordova
- iOS原生项目集成Cordova混合开发
- React Native 嵌入到iOS原生项目
- 将cordova嵌入iOS应用
- IOS搭建cordova项目
- cordova创建iOS项目
- React Native嵌入Android原生项目中
- React Native 嵌入到iOS原生应用
- iOS项目中加入cordova
- Android原生软件里嵌入一个基于cordova的网页页面(webview)
- cordova项目多个原生界面间过场动画配置
- React Native 嵌入原生项目混合开发-自定义RN Activity
- React-Native学习之嵌入Android原生项目
- 在 iOS创建 第一个Cordova 项目
- 原生的iOS工程局部页面嵌入weex的view
- RN——嵌入到iOS原生应用
- iOS 在react-native中嵌入原生悬浮框
- ionic2中利用自定义cordova插件(Plugin)ts调iOS原生的值(iOS原生的值传给ts)
- ABBYY FineReader 14新增了什么(附功能对比表)
- BeanUtils介绍及其使用
- 八(1)3 矩阵压缩存储的实现与应用2
- iOS11适配tableview
- 第五周数据结构项目(一)——建立顺序栈算法库
- iOS原生项目嵌入Cordova
- less学习(六)— 关于带参数的Mixin
- 【图形周长】你需要走遍所有可联通的X!!
- 微电汇CEO王志国:大量零售数据碎片化,具有高价值的数据还处于沉睡状态
- 程序员之间的鄙视链
- JQuery3.1.1源码解读(二)【init构造器】
- AS3.0升级埋坑之路
- 第七周项目六C/C++数据结构实践——停车场模拟(栈和队列综合)
- 大数据24小时:地质局发布地质大数据共享平台,科大讯飞将语音识别植入腾讯小Q机器人