热修复和热更新
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