success run js on iOS
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricJSCoreExecutor.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricJSEngine.h"
|
||||
#import "DoricContext.h"
|
||||
|
||||
@interface ViewController ()
|
||||
|
||||
@@ -26,39 +26,17 @@ - (void)viewDidLoad {
|
||||
label.centerX = self.view.width/2;
|
||||
label.centerY = self.view.height/2;
|
||||
[self.view addSubview:label];
|
||||
// DoricJSCoreExecutor *jse = [[DoricJSCoreExecutor alloc] init];
|
||||
// @try{
|
||||
// NSString *ret = [jse loadJSScript:@"typef Reflect" source:@"test"];
|
||||
// NSLog(@"js result %@", ret);
|
||||
// }@catch(NSException *e){
|
||||
// NSLog(@"catch Exception: %@,reason is %@",e.name,e.reason);
|
||||
// }
|
||||
// DoricLog(@"%@",@"testxxxxx");
|
||||
// DoricLog(@"test2rwr");
|
||||
DoricJSEngine *jsengine = [[DoricJSEngine alloc] init];
|
||||
[self test:@"method",@"1",@"2",nil];
|
||||
|
||||
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test:)];
|
||||
[label addGestureRecognizer:recognizer];
|
||||
label.userInteractionEnabled = YES;
|
||||
}
|
||||
|
||||
- (void)test:(UIView *)view {
|
||||
NSLog(@"test");
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"];
|
||||
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||
NSLog(@"%@",jsContent);
|
||||
DoricContext *context = [[DoricContext alloc] initWithScript:jsContent source:@"demo"];
|
||||
[context callEntity:@"log",nil];
|
||||
}
|
||||
|
||||
-(void)test:(NSString *)method,... {
|
||||
va_list args;
|
||||
va_start(args, method);
|
||||
[self test2:method args:args];
|
||||
va_end(args);
|
||||
}
|
||||
-(void)test2:(NSString *)method args:(va_list)args {
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
id arg = va_arg(args, id);
|
||||
while(arg != nil){
|
||||
[array addObject:arg];
|
||||
arg = va_arg(args, id);
|
||||
}
|
||||
for(id obj in array){
|
||||
DoricLog(@"test:%@",obj);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user