熱更新和熱修複 個人小結,熱更新修複小結
熱修複和熱更新
1 熱更新和熱修複:線上修複程式的 BUG
2 JSPach 的使用原理: OC 是一門動態運行時的語言,方法的運行和對象的建立是在運行時中建立的.JSPatch 正的用運行時,通過JavaScriptCore.framework作為 JS引擎,從 JS 動態調用方法和對象到OC 中,再作用NSInvocation動態調用對應的方法.例
Class class = NSClassFromString(@"UIViewController");
id controller = [class new];
SEL selector = NSSelectorFromString(@"viewDidLoad");
[controller performSelector:selector];
3 使用步驟
把JSPatch這個檔案夾拖入到檔案中然後將在 gitHub 下載的dome.js檔案拖入到項目中,在 APPDelegate中:
#import "AppDelegate.h"
#import "JPEngine.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[JPEngine startEngine];
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"demo.js" ofType:nil];
[JPEngine evaluateScriptWithPath:jsPath];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ViewController *rootViewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@end
並在 ViewController.m 中實現
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 50)];
[btn setTitle:@"Push JPTableViewController" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(handleBtn:) forControlEvents:UIControlEventTouchUpInside];
[btn setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:btn];
}
- (void)handleBtn:(UIButton *)btn {
}
最後將 dome.js 中的 JSViewController 改為 ViewController 即可
React Native
掃盲:是一種可以同時操作前段,後台,移動端都能即時更新開發的技術
注:通過 JavaSript運行時來建立JavaSript的代碼
具體運用這篇文章寫的很好 連結: https://zhuanlan.zhihu.com/p/19996445