iOS热修复---JSPatch简单修改
2017-02-23 本文已影响0人
ray_1942
1.用cocoaPods导入JSPatch的framework,习惯性的command+b编译一下
#添加热修复
pod'JSPatchPlatform'
2.在AppDelegate中导入头文件
import JSPatch / import JSPatchPlatform
#import <JSPatch/JSPatch.h>
3.在正式将热修复的代码上传之前最好先本地测试一下
1>将main.js文件放到项目的文件夹中
2>在appdelegate的func application(application:UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?)方法里添加以下代码
#if DEBUG
JSPatch.testScriptInBundle()
#else
JSPatch.startWithAppKey(JSPatch_key);
JSPatch.sync()
#endif
4.本地测试没问题的话就可以上传main.js
1>

2>

3>

4>添加app版本

5>

6>

选择main.js,选中全量下发的话就可以了
附带一个测试的js代码(修改项目中ViewController的testFunction方法)
require('UIColor')
defineClass('项目名.ViewController', {
testFunction:function() {
varredColor = UIColor.redColor();
self.view().setBackgroundColor(redColor);
}
})