JSPatchiOS App 熱更新服務(wù)平臺
JSPatch 可以讓你用 JavaScript 書寫原生 iOS APP。只需在項目引入極小的引擎,就可以使用 JavaScript 調(diào)用任何 Objective-C 的原生接口,獲得腳本語言的優(yōu)勢:為項目動態(tài)添加模塊,或替換項目原生代碼動態(tài)修復(fù) bug。
例如線上 APP 有一段代碼出現(xiàn) bug 導(dǎo)致 crash:
@implementation JPTableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *content = self.dataSource[[indexPath row]]; //可能會超出數(shù)組范圍導(dǎo)致crash
JPViewController *ctrl = [[JPViewController alloc] initWithContent:content];
[self.navigationController pushViewController:ctrl];
}
...
@end
可以通過下發(fā)這樣一段 JS 代碼,覆蓋掉原方法,修復(fù)這個 bug:
//JS
defineClass("JPTableViewController", {
//instance method definitions
tableView_didSelectRowAtIndexPath: function(tableView, indexPath) {
var row = indexPath.row()
if (self.dataSource().length > row) { //加上判斷越界的邏輯
var content = self.dataArr()[row];
var ctrl = JPViewController.alloc().initWithContent(content);
self.navigationController().pushViewController(ctrl);
}
}
}, {})
除了修復(fù) bug,JSPatch 也可以用于動態(tài)運營,實時修改線上 APP 行為,或動態(tài)添加功能。
評論
圖片
表情
