forked from TomSwift/UIWebView-TS_JavaScriptContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSViewController.m
More file actions
64 lines (49 loc) · 1.71 KB
/
TSViewController.m
File metadata and controls
64 lines (49 loc) · 1.71 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
//
// TSViewController.m
// testWebViewJSC
//
// Created by Nicholas Hodapp on 11/22/13.
// Copyright (c) 2013 CoDeveloper, LLC. All rights reserved.
//
#import "TSViewController.h"
#import "UIWebView+TS_JavaScriptContext.h"
@protocol JS_TSViewController <JSExport>
- (void) sayGoodbye;
@end
@interface TSViewController () <TSWebViewDelegate, JS_TSViewController>
@end
@implementation TSViewController
{
IBOutlet UIWebView* _webView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL* htmlURL = [[NSBundle mainBundle] URLForResource: @"testWebView"
withExtension: @"htm"];
[_webView loadRequest: [NSURLRequest requestWithURL: htmlURL]];
}
- (void)webView:(UIWebView *)webView didCreateJavaScriptContext:(JSContext *)ctx
{
ctx[@"sayHello"] = ^{
dispatch_async( dispatch_get_main_queue(), ^{
UIAlertView* av = [[UIAlertView alloc] initWithTitle: @"Hello, World!"
message: nil
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[av show];
});
};
ctx[@"viewController"] = self;
}
- (void) sayGoodbye
{
UIAlertView* av = [[UIAlertView alloc] initWithTitle: @"Goodbye, World!"
message: nil
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[av show];
}
@end