导航:首页 > 编程语言 > weex调用js

weex调用js

发布时间:2025-09-12 08:55:26

『壹』 weex 在ios怎么调用.we文件

项目初始化1、没有现成的工程的话新建ios项目命令行cd到项目根目录 执行 pod init,会创建一个pod配置文件用编辑器打开,加上 pod 'WeexSDK', :path=>'./sdk/'

/weex在ios目录下有个sdk文件夹,把它复制到ios项目根目录,和podFile里配置的路径一致关掉xcode,在当前目录,命令行执行pod install,现在项目目录变成了这样,以后点击xcworkspace文件打开项目创建一个新目录weex,命令行cd到weex目录,执行weex init,会提示你输入项目名称自动创建的文件:

在当前目录命令行执行npm install,安装依赖库创建一个文件夹js,命令行执行weex src -o js生成最终需要的js文件也可以weex src/main.we在浏览器预览或者weex src/main.we --qr 生成二维码,用playground App 扫描预览加载weex页面xcode打开workspace项目文件打开AppDelegate.m添加一下内容将之前创建的js文件夹拖到xcode工程的文件列表效果是这样的weex视图控制器的初始化ViewController.h:

[objc] view plain 在CODE上查看代码片派生到我的代码片//// ViewController.h// weexDemo3//// Created by admin on 16/8/3.

// Copyright ? 2016年 admin. All rights reserved.

//#import <UIKit/UIKit.h>

@interface ViewController : UIViewController- (instancetype)initWithJs:(NSString *)filePath;@endViewController.m:

[objc] view plain 在CODE上查看代码片派生到我的代码片//// ViewController.m// weexDemo3//// Created by admin on 16/8/3.

// Copyright ? 2016年 admin. All rights reserved.

//#import "ViewController.h"#import <WeexSDK/WXSDKInstance.h>

@interface ViewController ()@property (nonatomic, strong) WXSDKInstance *instance;@property (nonatomic, strong) UIView *weexView;@end@implementation ViewController{NSURL *jsUrl;}

- (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);jsUrl=[NSURL URLWithString:path];}

return self;}

- (void)viewDidLoad {[super viewDidLoad];_instance = [[WXSDKInstance alloc] init];_instance.viewController = self;_instance.frame=self.view.frame;__weak typeof(self) weakSelf = self;_instance.onCreate = ^(UIView *view) {[weakSelf.weexView removeFromSuperview];weakSelf.weexView = view;[weakSelf.view addSubview:weakSelf.weexView];};_instance.onFailed = ^(NSError *error) {NSLog(@"加载错误");};_instance.renderFinish = ^ (UIView *view) {NSLog(@"加载完成");};if (!jsUrl) {return;}

[_instance renderWithURL: jsUrl];self.view.backgroundColor=[UIColor whiteColor];}

- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.

}

- (void)dealloc{[_instance destroyInstance];}

@end再打开AppDelegate成都软件开发公司http://www.yingtaow.com?chidcd创建导航控制器引入头文件#import "ViewController.h"创建导航视图:

[objc] view plain 在CODE上查看代码片派生到我的代码片- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//weex[self initWeex];ViewController *vc=[[ViewController alloc]initWithJs:@"main.js"];UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];self.window.rootViewController=nav;return YES;}

运行图片不显示是因为图片加载需要自己创建模块,可以直接把demo的代码和pod配置粘过来使用

阅读全文

与weex调用js相关的资料

热点内容
概率与编程学什么专业好 浏览:163
java创建一个account 浏览:53
js弹出选择文件 浏览:400
stc8开发板用什么软件编程 浏览:303
微信怎么邦卡 浏览:232
安卓刷机工具哪个好 浏览:443
2008r2忘记登录密码 浏览:187
比较好的起名网站有哪些 浏览:703
mkv音轨分离工具 浏览:286
怎么创建acc版本 浏览:182
word2007点保存没用 浏览:693
三菱编程流水线指令怎么打 浏览:186
图片颜色配置文件哪个最清晰 浏览:898
下划线代码 浏览:434
市级转发省级转发国家的文件格式 浏览:539
无法进入网络引导系统安装 浏览:502
office2016提示文件损坏 浏览:773
淘宝专业版店招代码 浏览:837
握手包文件下载 浏览:575
excel文件突然变成白色 浏览:350

友情链接