導航:首頁 > 編程語言 > 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相關的資料

熱點內容
word2007奇偶頁眉一樣 瀏覽:573
車載app管家有哪些 瀏覽:279
少數派app是什麼意思 瀏覽:690
php執行外部程序 瀏覽:505
ug倒角如何編程分兩刀 瀏覽:217
matlab讀取文件路徑 瀏覽:534
概率與編程學什麼專業好 瀏覽:163
java創建一個account 瀏覽:53
js彈出選擇文件 瀏覽:400
stc8開發板用什麼軟體編程 瀏覽:303
微信怎麼邦卡 瀏覽:232
安卓刷機工具哪個好 瀏覽:443
2008r2忘記登錄密碼 瀏覽:187
比較好的起名網站有哪些 瀏覽:703
mkv音軌分離工具 瀏覽:286
怎麼創建acc版本 瀏覽:182
word2007點保存沒用 瀏覽:693
三菱編程流水線指令怎麼打 瀏覽:186
圖片顏色配置文件哪個最清晰 瀏覽:898
下劃線代碼 瀏覽:434

友情鏈接