熱更新和熱修復 我的小結

熱修復和熱更新git

1 熱更新和熱修復:在線修復程序的 BUGapp

2 JSPach 的使用原理: OC 是一門動態運行時的語言,方法的運行和對象的建立是在運行時中建立的.JSPatch 正的用運行時,經過JavaScriptCore.framework做爲 JS引擎,從 JS 動態調用方法和對象到OC 中,再做用NSInvocation動態調用對應的方法.例dom

    Class class = NSClassFromString(@"UIViewController");ide

    id controller = [class new];lua

    SEL selector = NSSelectorFromString(@"viewDidLoad");orm

    [controller performSelector:selector];對象

3 使用步驟ip

            把JSPatch這個文件夾拖入到文件中而後將在 gitHub 下載的dome.js文件拖入到項目中,在 APPDelegate中:開發

#import "AppDelegate.h"get

#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

相關文章
相關標籤/搜索