這個(gè)是官網(wǎng)http://jspatch.com/
一個(gè)輕量級(jí)的熱修復(fù)工具,按照官網(wǎng)配置一下也就那么幾行代碼,就可以輕松配置好。
首先建好一個(gè)工程
將下載的包拖進(jìn)來
下面導(dǎo)入系統(tǒng)依賴庫(kù)
jspatch庫(kù)是拖進(jìn)去就會(huì)自動(dòng)加載進(jìn)去的
然后就是在appdelegate里面的配置
上面分別代表的是測(cè)試環(huán)境和正式環(huán)境,不懂得百度一下
下面就可以愉快的寫代碼了
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2ca2}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}span.s1 {font-variant-ligatures: no-common-ligatures; color: #78492a}span.s2 {font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s4 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s5 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s7 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s8 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s9 {font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b}
#import "ViewController.h"
@interface ViewController ()
/**
* <#Description#>
*/
@property(nonatomic,strong)NSArray *array;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 100, 200, 50);
[btn setTitle:@"觸發(fā)崩潰事件" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor redColor];
[btn addTarget:self action:@selector(bugEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)bugEvent{
NSArray *arr = [NSArray array];
NSString *str = arr[10];
}
@end
這個(gè)就會(huì)觸發(fā)一個(gè)數(shù)組越界的錯(cuò)誤
有人會(huì)說這么簡(jiǎn)單改一下不就好了,但是假如這個(gè)項(xiàng)目上線了呢?
所用用戶因?yàn)檫@么一個(gè)小的錯(cuò)誤全部閃退,體驗(yàn)效果肯定很差了
這個(gè)時(shí)候jspatch就應(yīng)運(yùn)而生了
首先我們創(chuàng)建一個(gè)main.js文件
打開這個(gè)文件
下面我們開始編寫代碼了
defineClass('ViewController', {
bugEvent:function() {
var array = NSArray.arrayWithObjects("as", "ss", null);
var str = array().objectAtIndex(1);
console.log(str);
},
})
再次運(yùn)行就不會(huì)崩潰了
什么!這么寫很費(fèi)勁,沒問題我給你提供兩種方案
*http://bang590.github.io/JSPatchConvertor/ 這個(gè)可以將oc代碼轉(zhuǎn)換成js代碼
什么,打開網(wǎng)頁(yè)比較慢,們問題還有
這個(gè)是代碼提示插件,找不到的自行百度一下
這個(gè)是線下測(cè)試下面就是線上測(cè)試
我們新建一個(gè)項(xiàng)目
我們打開它
點(diǎn)擊添加app版本輸入你目前app的版本號(hào)
點(diǎn)擊打開
選中你的main.js文件進(jìn)行上傳,簡(jiǎn)單吧。模擬測(cè)試記得把DEBUG改成release
就這么多吧,就是一個(gè)簡(jiǎn)單的入門的小應(yīng)用,歡迎大家指正。