What is hot update?
For example, if you have an app and suddenly want to add a little feature, you have two options
- The first way: modify the source code in native code and submit it to the appStore, which is a long process… Although I’ve been getting feedback within a day or two on my latest submissions, there’s no guarantee that Apple’s service will always be this good. There may be no time for your review in 10 days and half a month. I call this a cold update!
- The second way is to use some third-party platforms. Wax is now popular before JSPatch. withwebsiteThe introduction of
JSPatch is an open source project (Github link) that can use JavaScript to call any Objective-C native interface instead of any Objective-C native method by introducing minimal engine files into the project. Currently, it is mainly used to deliver JS scripts to replace native Objective-C code and fix online bugs in real time.
Here’s what I learned: You can fix minor problems without having to re-upload your app to the Appstore! Greatly improve the efficiency of development and maintenance
JSPatch SDK access
JSPatch basic usage
Finally, print a HelloWorld using the JSPatch platform
- Local test
#import "ViewController.h"
static NSString *identifer = @"cellID";
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// NSLog(<#NSString * _Nonnull format, ... # >)
[self.view addSubview:self.tableView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableView *)tableView {
if(! _tableView) { _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; _tableView.dataSource = self; _tableView.delegate = self; [_tableView registerClass:[UITableViewCell class]forCellReuseIdentifier:identifer];
}
return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
cell.textLabel.text = [NSString stringWithFormat:@"Line %ld", indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"OC-- line %ld", indexPath.row);
}
@end
Copy the code
//APPDelete.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// [JSPatch startWithAppKey:@"891dfb388fe263a1"];
// [JSPatch sync];
[JSPatch testScriptInBundle];
return YES;
}
Copy the code
- Then add the main.js file
defineClass("ViewController", {
tableView_didSelectRowAtIndexPath: function(tableView, indexPath) {
console.log("JSPath--:",indexPath.row()); }})Copy the code
The main. Js file above is at app startup time! Is automatically called: the function is to override this method in the ViewController
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"OC-- line %ld", indexPath.row);
}
Copy the code
Before calling the main.js file
The program runs like this
After calling the main.js file
The program runs like this
By now you can see how powerful JSPatch is! This is just a local test. You have to modify the main.js file locally when you want to modify the program content
Online test (basically upload main.js file to JSPathch background)
Then modify the code in appDelete.m
//APPDelete.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for// 891DFb388FE263A1 This is the appKey that was automatically generated when you created your application in the JSPatch background"891dfb388fe263a1"];
[JSPatch sync];
// [JSPatch testScriptInBundle]; /** Delete the local main.js file */return YES;
}
Copy the code