JSPath修復的具體步驟就是: 在main.js文件里面, 完成你要對哪個文件 + 哪個方法里面的操作進行修改, 然后先進行本地補丁修復, 然后將main.js文件傳到JSPath上對應得APP應用上, 完成網上的修復。
下面開始吧。。。。。
首先, 登錄JSPath官網注冊賬號
http://jspatch.com
第一步: 新增APP獲取Appkey
新增
輸入APP的名字
app名字
獲得AppKey
appKey
第二步: 到程序中設置
one: 到gitHUb上下載SDK
https://github.com/bang590/JSPatchPlatform.git
下載 SDK 后解壓,將 JSPatchPlatform.framework 拖入項目中,勾選 "Copy items if needed",并確保 "Add to target" 勾選了相應的 target。
*添加 libz.dylib 和 JavaScriptCore.framework。
導入框架
two:
在 AppDelegate.m 里載入文件,并調用 +startWithAppKey: 方法,參數為第一步獲得的 AppKey。接著調用 +sync 方法檢查更新。例子:
#import "AppDelegate.h"
//第一步: 引入頭文件
#import <JSPatchPlatform/JSPatch.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//APPKey: e948b3f13342d77d
//本地補丁測試時關掉下面兩個方法
[JSPatch startWithAppKey:@"e948b3f13342d77d"];
[JSPatch sync];
//至此 JSPatch 接入完畢,下一步可以開始在后臺為這個 App 添加 JS 補丁文件了。
//發布前進行本地補丁測試用的(本地補丁上傳到網上時不能帶有中文注釋,否則不成功。 而且最好執行兩遍才會有效果)
//[JSPatch testScriptInBundle];
return YES;
}
three:在ViewController中添加一個label
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.backgroundColor = [UIColor redColor];
label.text =@"aaa";
[self.view addSubview:label];
}```
#####four: 新建一個main.js 文件, 在里面完成補丁工作
在上傳修復文件的時候, 最好不要有中文注釋, 否則修復不成功
719E0692-4BC2-4C92-9F36-79CDB13347E6.png
defineClass("ViewController", {
viewDidLoad:function(){
}
})```
- 首先打開Appdelegate中的
[JSPatch testScriptInBundle];
方法, 測試本地補丁修復結果, 若修復成功繼續下一步。。。 - 將main.js文件從工程中移除去, 放到桌面上
- 在JSPath中,打開剛剛新建的APP
上傳補丁
719E0692-4BC2-4C92-9F36-79CDB13347E6.png
FD43C3D0-DE09-4FB5-91C6-6AFBF5A2CDF3.png
上傳剛才的main.js補丁文件
3071BF3F-725D-43A1-8900-8E7A7CFA3C3F.png
完成修復嘍 ~