JSPatch 热更新
参考文档
jspatch语法
JSPatchConvertor
这个转换代码不能直接使用
原理
装换工具 (js对象转oc对象)
// JSChange.h
#import <Foundation/Foundation.h>
@interface JSChange : NSObject
+ (instancetype)boxObj:(id)obj;
@end
// JSChange.m
#import "JSChange.h"
@interface JSChange ()
@property (nonatomic) id obj;
@end
@implementation JSChange
+ (instancetype)boxObj:(id)obj
{
JSChange *boxing = [[JSChange alloc] init];
boxing.obj = obj;
return boxing;
}
@end
//用法
JSChange.boxObj("www.Q1231321132Q.com").obj()
嵌入项目代码
target 'MIOS' do
platform :ios, '8.0'
pod "JSPatch"
end
[JPEngine startEngine];
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"mq" ofType:@"js"];
NSString *script = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil];
[JPEngine evaluateScript:script];
require('UIColor,NSString,NSURLRequest,NSURL,JSChange');
defineClass('WebTest', {
// viewDidLoad: function() {
//// 原来的方法
//// self.ORIGviewDidLoad();
//// 重写方法
// self.super().viewDidLoad();
// self.view().addSubview(self.HttpField());
// self.view().addSubview(self.MWebView());
// self.view().addSubview(self.GoBtn());
// self.view().setBackgroundColor(UIColor.lightGrayColor());
// self.HttpField().setFrame({x:20, y:20, width:100, height:20});
// self.HttpField().setText(JSChange.boxObj("www.Q1231321132Q.com").obj());
// },
openClick: function() {
var urlString = NSString.stringWithFormat("http://%@", self.getHttp());
console.log(urlString.toJS());
var req = NSURLRequest.requestWithURL(NSURL.URLWithString(urlString));
self.MWebView().WebView().loadRequest(req);
self.endEditing();
},
});