iOS集成weex(0)
来源:互联网 发布:羽毛球计分软件 编辑:程序博客网 时间:2024/05/23 20:03
命令行cd到项目根目录 执行 pod init,会创建一个pod配置文件
用编辑器打开,加上 pod ‘WeexSDK’, :path=>’./sdk/’
下载最新的weexSDK https://github.com/alibaba/weex
在ios目录下有个sdk文件夹,把它复制到ios项目根目录,和podFile里配置的路径一致
关掉xcode,在当前目录,命令行执行pod install,
现在项目目录变成了这样,以后点击xcworkspace文件打开项目
创建一个新目录weex,命令行cd到weex目录,执行weex init,会提示你输入项目名称
在当前目录命令行执行npm install,安装依赖库
创建一个文件夹js,命令行执行weex compile src js -w生成最终需要的js文件
也可以weex src/main.we在浏览器预览
或者weex src/main.we –qr 生成二维码,用playground App 扫描预览
加载weex页面
xcode打开workspace项目文件
打开AppDelegate.m添加一下内容
将之前创建的js文件夹拖到xcode工程的文件列表
weex视图控制器的初始化
ViewController.h:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController- (instancetype)initWithJs:(NSString *)filePath;@end
ViewController.m:
#import "ViewController.h"#import <WeexSDK/WXSDKInstance.h>@interface ViewController ()@property (nonatomic, strong) WXSDKInstance *instance;@property (nonatomic, strong) UIView *weexView;@property (nonatomic, strong) NSURL *jsUrl;@end@implementation ViewController- (instancetype)initWithJs:(NSString *)filePath { self = [super init]; if(self){ //远程js文件 // NSString *path=[NSString stringWithFormat:@"http://192.168.232.13:8080/examples/js/%@",filePath]; //本地js文件 NSString *path=[NSString stringWithFormat:@"file://%@/js/%@",[NSBundle mainBundle].bundlePath,filePath]; NSLog(@"-----path:%@",path); self.jsUrl=[NSURL URLWithString:path]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; self.instance = [[WXSDKInstance alloc] init]; self.instance.viewController = self; self.instance.frame=self.view.frame; __weak typeof(self) weakSelf = self; self.instance.onCreate = ^(UIView *view) { [weakSelf.weexView removeFromSuperview]; weakSelf.weexView = view; [weakSelf.view addSubview:weakSelf.weexView]; }; self.instance.onFailed = ^(NSError *error) { NSLog(@"加载错误"); }; self.instance.renderFinish = ^ (UIView *view) { NSLog(@"加载完成"); }; if (!self.jsUrl) { return; } [self.instance renderWithURL: self.jsUrl]; self.view.backgroundColor=[UIColor whiteColor];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (void)dealloc { [self.instance destroyInstance];}@end
创建视图:
#import "AppDelegate.h"#import <WeexSDK/WeexSDK.h>#import "ViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (void)initWeex { //business configuration [WXAppConfiguration setAppGroup:@"AliApp"]; [WXAppConfiguration setAppName:@"WeexDemo"]; [WXAppConfiguration setAppVersion:@"1.0.0"];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [self initWeex]; ViewController *vc = [[ViewController alloc] initWithJs:@"foo.js"]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc]; self.window.rootViewController = navi; return YES;}- (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end
xcode运行,至此集成结束,下一节总结开发基础
阅读全文
0 0
- iOS集成weex(0)
- IOS项目集成Weex
- iOS集成Weex
- weex 集成到iOS
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- Weex项目初始化weex-iOS集成
- iOSweex集成入门,weex快速上手教程,weex集成到iOS工程注意事项(一)
- Weex iOS SDK 集成指南
- 阿里weex研究iOS(二)已有项目集成
- Weex iOS 端集成的一些感想
- Android项目集成Weex
- weex 集成记录
- native给weex页面传值以及Weex调用native方法(iOS端)
- 阿里weex研究iOS(零)从0开始跑helloword
- iOS weex~Apache
- Java文件操作
- NAT技术与代理服务器调研
- hdu6058-Kanade's sum
- SVN Checkout 问题 The XML response contains invalid XML
- elasticsearch5.2 集群
- iOS集成weex(0)
- properties文件配置
- SharedPreference的使用以及commit()和apply()的区别
- 拼多多笔试题总结
- hisi SDK安装记录
- SpringBoot之文件下载
- OpenCV学习(7) 分水岭算法(1)
- EF异常:对一个或多个实体的验证失败
- C++实例化对象数组