這個是官網http://jspatch.com/
一個輕量級的熱修復工具,按照官網配置一下也就那么幾行代碼,就可以輕松配置好。
首先建好一個工程
將下載的包拖進來
3C01E269-0462-4E26-A0BE-76FD6954FE5B.png
下面導入系統依賴庫
534FF0AD-6907-4DC2-89CA-6742A2DCEB3D.png
jspatch庫是拖進去就會自動加載進去的
然后就是在appdelegate里面的配置
8F703DCF-58FA-4261-82C7-883E4E2F57EE.png
上面分別代表的是測試環境和正式環境,不懂得百度一下
下面就可以愉快的寫代碼了
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:@"觸發崩潰事件" 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
這個就會觸發一個數組越界的錯誤
有人會說這么簡單改一下不就好了,但是假如這個項目上線了呢?
所用用戶因為這么一個小的錯誤全部閃退,體驗效果肯定很差了
這個時候jspatch就應運而生了
首先我們創建一個main.js文件
A7C6AFEC-19B4-4AB0-9C76-FDCB3F9C5802.png
748DC448-637A-41E5-ACCB-0E7B3FBEAC07.png
打開這個文件
8BC27868-F65C-4242-95D8-1CEDD97AE375.png
下面我們開始編寫代碼了
defineClass('ViewController', {
bugEvent:function() {
var array = NSArray.arrayWithObjects("as", "ss", null);
var str = array().objectAtIndex(1);
console.log(str);
},
})
再次運行就不會崩潰了
什么!這么寫很費勁,沒問題我給你提供兩種方案
*http://bang590.github.io/JSPatchConvertor/ 這個可以將oc代碼轉換成js代碼
什么,打開網頁比較慢,們問題還有
590EAAE3-35D5-4945-8BB7-8CA622F02F86.png
這個是代碼提示插件,找不到的自行百度一下
這個是線下測試下面就是線上測試
我們新建一個項目
DD202A99-EF6C-4999-8D45-806544DC7D64.png
我們打開它
A3C4CA94-7433-4ED9-B329-C84BF3E08039.png
點擊添加app版本輸入你目前app的版本號
1263CFA7-FF68-463A-8914-EA20250736D3.png
點擊打開
7D41410E-8A7E-4A5A-B4D2-6C611293ADBF.png
選中你的main.js文件進行上傳,簡單吧。模擬測試記得把DEBUG改成release
E11CA280-8356-40A4-B2E7-1134DF4138CE.png
就這么多吧,就是一個簡單的入門的小應用,歡迎大家指正。