IOS项目集成Weex
来源:互联网 发布:网络攻防大赛 编辑:程序博客网 时间:2024/06/06 02:51
安装homebrew
通过homebrew安装nodejs
通过npm安装weex-toolkit
npm install -g weex-toolkit
安装cocoapod
通过xcode创建项目WeexDemo
在WeexDemo目录下执行pod init创建Podfile文件
编辑Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'WeexDemo'do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for WeexDemo
pod 'WeexSDK','0.9.5'
end
执行命令pod install
创建文件hello.we
<template>
<div class="wrapper">
<text class="weex">Hello Weex !</text>
<text class="vue">Hello Vue !</text>
</div>
</template>
<style scoped>
.wrapper {
flex-direction: column;
justify-content: center;
}
.weex {
font-size: 60px;
text-align: center;
color: #1B90F7;
}
.vue {
font-size: 60px;
text-align: center;
margin-top: 30px;
color: #41B883;
}
</style>
执行命令
weex hello.we -o hello.js
把生成的hello.js加入项目工程
编辑AppDelegate.m文件
#import <WeexSDK/WeexSDK.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//business configuration
[WXAppConfigurationsetAppGroup:@"AliApp"];
[WXAppConfigurationsetAppName:@"WeexDemo"];
[WXAppConfigurationsetAppVersion:@"1.0.0"];
//init sdk enviroment
[WXSDKEngineinitSDKEnviroment];
//register custom module and component,optional
//[WXSDKEngine registerComponent:@"MyView" withClass:[MyViewComponent class]];
//[WXSDKEngine registerModule:@"event" withClass:[WXEventModule class]];
//register the implementation of protocol, optional
//[WXSDKEngine registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)];
//set the log level
[WXLogsetLogLevel: WXLogLevelAll];
returnYES;
}
编辑ViewController.h文件
#import <UIKit/UIKit.h>
#import <WeexSDK/WXSDKInstance.h>
@interface ViewController :UIViewController
@property (nonatomic,strong) WXSDKInstance * instance;
@property (nonatomic,strong) UIView * weexView;
@property (nonatomic,strong) NSURL * url;
@end
编辑ViewController.m文件
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_instance = [[WXSDKInstancealloc] init];
_instance.viewController =self;
_instance.frame =self.view.frame;
__weaktypeof(self) weakSelf =self;
_instance.onCreate = ^(UIView *view) {
[weakSelf.weexViewremoveFromSuperview];
weakSelf.view = view;
[weakSelf.viewaddSubview:weakSelf.weexView];
};
_instance.onFailed = ^(NSError *error) {
//process failure
};
_instance.renderFinish = ^ (UIView *view) {
//process renderFinish
};
self.url = [[NSBundlemainBundle] URLForResource:@"hello"withExtension:@"js"];
[_instancerenderWithURL:self.url];
}
- (void)dealloc {
[_instancedestroyInstance];
}
运行程序
源代码工程
https://github.com/chenhaifeng2016/WeexDemoIOS
- IOS项目集成Weex
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Android项目集成Weex
- iOS集成Weex
- weex 集成到iOS
- 阿里weex研究iOS(二)已有项目集成
- Weex iOS SDK 集成指南
- iOS集成weex(0)
- Weex iOS 端集成的一些感想
- iOSweex集成入门,weex快速上手教程,weex集成到iOS工程注意事项(一)
- weex 集成记录
- iOS项目集成LinPhone
- iOS项目集成cocoaPods
- iOS项目集成LinPhone
- 架构设计:系统间通信(15)——服务治理与Dubbo 上篇
- 浅析Apache Spark Caching和Checkpointing
- Spring security实现权限管理
- 项目架构分析-web.xml文件解读
- Linux df du的区别
- IOS项目集成Weex
- [leetcode-二叉树后序遍历]--145. Binary Tree Postorder Traversal
- JS中call()和apply()的目的及用法
- display和visibility的用法区别
- 如何利用fleet单元文件为CoreOS集群创建高灵活性服务
- js计算两个日期相差天数
- window下安装redis cluster 集群
- 架构设计:系统间通信(16)——服务治理与Dubbo 中篇(预热)
- View体系之View的滑动