iOS热更新_无需发布新版本实现app更新

实现热更新的方法:

  1. 使用FaceBook 的开源框架 reactive native
  2. 使用JSpatch

JSPatch 学习总结

  以下内容为学习总结记录。JSPatch是实现热更新(无需发新版本实现app添加新功能)的一个框架。可以为项目动态添加模块,或替换项目原生代码动态修复 bug。比较其他的热更新方法,学习成本更低。JSPatch坐着给出的说明文档非常详细,网址:

JSPatch下载地址:https://github.com/bang590/JSPatch
讲述JSPatch:http://blog.cnbang.net/
使用说明文档介绍:https://github.com/bang590/JSPatch/wiki

JSPatch的使用简记:

//JSPatch的三个文件导入项目,在需要的地方加入以下代码
[JPEngine startEngine];
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js"];
NSString *script = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil];
[JPEngine evaluateScript:script];

ViewController中的button事件

- (void)setButtonAction:(UIButton *)sender {
    self.view.backgroundColor = [UIColor redColor];
}

使用JS改变button事件的写法:

require('UILabel, UIColor, UIFont')

defineClass('ViewController', {
setButtonAction: function(sender) {
    var viewController = XYViewController.alloc().init()       self.navigationController().pushViewController_animated(viewController,YES)
}

})

defineClass('XYViewController:UIViewController',{
viewDidLoad:function() {
    self.ORIGviewDidLoad();
    var whiteColor = UIColor.whiteColor();
    var view = self.view()
    view.setBackgroundColor(whiteColor);

    var lab = UILabel.alloc().initWithFrame({x: 10, y: 150, width: 100, height: 30});
    lab.setText("happy");
    lab.setTextAlignment(2)
    self.view().addSubview(lab);

},

})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值