forked from Irrelon/iOS-JavaScript-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSCDemoViewController.mm
More file actions
130 lines (97 loc) · 3.03 KB
/
JSCDemoViewController.mm
File metadata and controls
130 lines (97 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// JSCDemoViewController.m
// JSCDemo
//
// Created by Rob Evans
// Copyright 2011 Irrelon Software Limited
// http://www.isogenicengine.com
#import "JSCDemoViewController.h"
#import "JSCBinding.h"
@implementation JSCDemoViewController
@synthesize log;
@synthesize input;
@synthesize execButton;
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[JSCBinding shareInstance].delegate = self;
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(IBAction) press:(id) sender
{
NSString* result = nil;
UIButton* button =(UIButton*) sender;
NSString* text = button.titleLabel.text;
if ([text isEqualToString:@"clean"]) {
log.text = @"";
return;
}
if ([text isEqualToString:@"test1"]) {
result = [[JSCBinding shareInstance] execJavaScrpt:@"test1();"];
}
if ([text isEqualToString:@"test2"]) {
result = [[JSCBinding shareInstance] execJavaScrpt:@"test2();"];
}
if ([text isEqualToString:@"test3"]) {
result = [[JSCBinding shareInstance] execJavaScrpt:@"print(callObjc('call callObjc directly'));"];
}
if ([text isEqualToString:@"test4"]) {
result = [[JSCBinding shareInstance] execJavaScrpt:@"test4();"];
}
if ([text isEqualToString:@"exec"]) {
result = [[JSCBinding shareInstance] execJavaScrpt:input.text];
}
if ([text isEqualToString:@"Destroy"]) {
[JSCBinding attemptDealloc];
log.text = @"";
}
if ([text isEqualToString:@"Reload"]) {
//When you reload JS you must register delegate at first
[JSCBinding shareInstance].delegate = self;
[[JSCBinding shareInstance] load:[[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js" inDirectory:@"www"]];
}
NSLog(@"result:%@",result);
}
-(IBAction) textFiledDown:(id) sender
{
[sender resignFirstResponder];
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[[JSCBinding shareInstance] load:[[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js" inDirectory:@"www"]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSString*) execObjectC:(NSString*) msg
{
return [NSString stringWithFormat:@"execObjectC with msg : %@",msg];
//output.text = msg;
}
-(void) print:(NSString *)msg
{
log.text = [NSString stringWithFormat:@"%@\n%@",log.text,msg];
}
@end