weexStudio下载地址

  1. 安装weexlistener
    安装命令npm install weexlistener -g
    weexlistener用于监听本地文件,并建立一个websocket。端口号固定为29998。
    也可以自己写代码监听这个端口

  2. 安装concurrently
    在工程目录下
    安装命令 npm install concurrently -g
    用于npm同时执行两个命令

  3. 在安卓或者iOS代码中监听本地websocket端口29998
    iOS代码:

    1
    2
    3
    4
    NSURL *socketURL = [NSURL URLWithString:[NSString stringWithFormat:@"ws://%@:%@", ip, @"29998"]];
    self.hotReloadSocket = [[SRWebSocket alloc] initWithURL:socketURL protocols:@[@"echo-protocol"]];
    self.hotReloadSocket.delegate = self;
    [self.hotReloadSocket open];

    在receive回调方法中接受参数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    if ([@"refresh" isEqualToString:message]) {

    UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
    if(recordTime-_lastrefresh>300)
    {
    _lastrefresh=recordTime;
    DBWXBaseViewController *baseVC = self.navigationController.viewControllers.lastObject;
    [baseVC refresh];
    }

    }
  4. 配置weex工程 package.json
    修改script语句"ide:preview": "concurrently \"npm start\" \"weexls start\""

  5. 运行weexstudio
    编译结束后,每次保存都会自动刷新手机端界面