Skip to content

Commit 17fcf7a

Browse files
committed
Merge pull request marcuswestin#105 from lokimeyburg/wkwebview-support
WKWebView Support
2 parents b541394 + 35a8b7b commit 17fcf7a

18 files changed

+847
-239
lines changed

Example Apps/ExampleApp-OSX.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */; };
11+
0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */; };
1012
2C136A2517641106004C7401 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C136A2417641106004C7401 /* Cocoa.framework */; };
1113
2C136A2F17641106004C7401 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C136A2D17641106004C7401 /* InfoPlist.strings */; };
1214
2C136A3117641106004C7401 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C136A3017641106004C7401 /* main.m */; };
@@ -20,6 +22,10 @@
2022
/* End PBXBuildFile section */
2123

2224
/* Begin PBXFileReference section */
25+
0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridgeBase.h; sourceTree = "<group>"; };
26+
0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridgeBase.m; sourceTree = "<group>"; };
27+
0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewJavascriptBridge.h; sourceTree = "<group>"; };
28+
0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKWebViewJavascriptBridge.m; sourceTree = "<group>"; };
2329
2C136A2117641106004C7401 /* ExampleApp-OSX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ExampleApp-OSX.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2430
2C136A2417641106004C7401 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
2531
2C136A2717641106004C7401 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -118,6 +124,10 @@
118124
2C1562C1176BA9FF00B4AE50 /* WebViewJavascriptBridge */ = {
119125
isa = PBXGroup;
120126
children = (
127+
0ECB01451A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.h */,
128+
0ECB01461A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m */,
129+
0ECB01471A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.h */,
130+
0ECB01481A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m */,
121131
2C1562C2176BA9FF00B4AE50 /* WebViewJavascriptBridge.h */,
122132
2C1562C3176BA9FF00B4AE50 /* WebViewJavascriptBridge.js.txt */,
123133
2C1562C4176BA9FF00B4AE50 /* WebViewJavascriptBridge.m */,
@@ -192,6 +202,8 @@
192202
isa = PBXSourcesBuildPhase;
193203
buildActionMask = 2147483647;
194204
files = (
205+
0ECB01491A0EEB3A0037FF4E /* WebViewJavascriptBridgeBase.m in Sources */,
206+
0ECB014A1A0EEB3A0037FF4E /* WKWebViewJavascriptBridge.m in Sources */,
195207
2C136A3117641106004C7401 /* main.m in Sources */,
196208
2C1562C6176BA9FF00B4AE50 /* WebViewJavascriptBridge.m in Sources */,
197209
2C136A3817641106004C7401 /* AppDelegate.m in Sources */,

Example Apps/ExampleApp-OSX/AppDelegate.m

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@
99
#import "AppDelegate.h"
1010
#import <WebKit/WebKit.h>
1111
#import "WebViewJavascriptBridge.h"
12+
#import "WKWebViewJavascriptBridge.h"
1213

1314
@implementation AppDelegate {
1415
WebView* _webView;
16+
WKWebView *_WKWebView;
1517
WebViewJavascriptBridge* _bridge;
18+
WKWebViewJavascriptBridge* _WKBridge;
19+
NSView* _WKWebViewWrapper;
1620
}
1721

1822
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
1923
{
2024
[self _createViews];
21-
[self _createBridge];
22-
[self _createObjcButtons];
23-
[self _loadPage];
25+
[self _configureWebview];
26+
[self _configureWKWebview];
2427
}
2528

26-
- (void)_createBridge {
29+
- (void)_configureWebview {
30+
// Create Bridge
2731
_bridge = [WebViewJavascriptBridge bridgeForWebView:_webView handler:^(id data, WVJBResponseCallback responseCallback) {
2832
NSLog(@"ObjC received message from JS: %@", data);
2933
responseCallback(@"Response for message from ObjC");
@@ -39,22 +43,86 @@ - (void)_createBridge {
3943
}];
4044

4145
[_bridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }];
42-
}
4346

44-
- (void)_createObjcButtons {
47+
// Create Buttons
4548
NSButton *messageButton = [[NSButton alloc] initWithFrame:NSMakeRect(5, 0, 120, 40)];
4649
[messageButton setTitle:@"Send message"];
4750
[messageButton setBezelStyle:NSRoundedBezelStyle];
4851
[messageButton setTarget:self];
4952
[messageButton setAction:@selector(_sendMessage)];
50-
[_webView addSubview:messageButton];
51-
53+
[_webView addSubview:messageButton];
54+
5255
NSButton *callbackButton = [[NSButton alloc] initWithFrame:NSMakeRect(120, 0, 120, 40)];
5356
[callbackButton setTitle:@"Call handler"];
5457
[callbackButton setBezelStyle:NSRoundedBezelStyle];
5558
[callbackButton setTarget:self];
5659
[callbackButton setAction:@selector(_callHandler)];
5760
[_webView addSubview:callbackButton];
61+
62+
NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(235, 0, 180, 40)];
63+
[webViewToggleButton setTitle:@"Switch to WKWebView"];
64+
[webViewToggleButton setBezelStyle:NSRoundedBezelStyle];
65+
[webViewToggleButton setTarget:self];
66+
[webViewToggleButton setAction:@selector(_toggleExample)];
67+
[_webView addSubview:webViewToggleButton];
68+
69+
70+
// Load Page
71+
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
72+
NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
73+
[[_webView mainFrame] loadHTMLString:html baseURL:nil];
74+
}
75+
76+
77+
- (void)_configureWKWebview {
78+
// Create Bridge
79+
_WKBridge = [WKWebViewJavascriptBridge bridgeForWebView:_WKWebView handler:^(id data, WVJBResponseCallback responseCallback) {
80+
NSLog(@"ObjC received message from JS: %@", data);
81+
responseCallback(@"Response for message from ObjC");
82+
}];
83+
84+
[_WKBridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) {
85+
NSLog(@"testObjcCallback called: %@", data);
86+
responseCallback(@"Response from testObjcCallback");
87+
}];
88+
89+
[_WKBridge send:@"A string sent from ObjC before Webview has loaded." responseCallback:^(id responseData) {
90+
NSLog(@"objc got response! %@", responseData);
91+
}];
92+
93+
[_WKBridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }];
94+
95+
// Create Buttons
96+
NSButton *messageButton = [[NSButton alloc] initWithFrame:NSMakeRect(5, 0, 120, 40)];
97+
[messageButton setTitle:@"Send message"];
98+
[messageButton setBezelStyle:NSRoundedBezelStyle];
99+
[messageButton setTarget:self];
100+
[messageButton setAction:@selector(_WKSendMessage)];
101+
[_WKWebView addSubview:messageButton];
102+
103+
NSButton *callbackButton = [[NSButton alloc] initWithFrame:NSMakeRect(120, 0, 120, 40)];
104+
[callbackButton setTitle:@"Call handler"];
105+
[callbackButton setBezelStyle:NSRoundedBezelStyle];
106+
[callbackButton setTarget:self];
107+
[callbackButton setAction:@selector(_WKCallHandler)];
108+
[_WKWebView addSubview:callbackButton];
109+
110+
NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(235, 0, 180, 40)];
111+
[webViewToggleButton setTitle:@"Switch to WebView"];
112+
[webViewToggleButton setBezelStyle:NSRoundedBezelStyle];
113+
[webViewToggleButton setTarget:self];
114+
[webViewToggleButton setAction:@selector(_toggleExample)];
115+
[_WKWebView addSubview:webViewToggleButton];
116+
117+
// Load Page
118+
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
119+
NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
120+
[_WKWebView loadHTMLString:html baseURL:nil];
121+
}
122+
123+
-(void)_toggleExample {
124+
_WKWebView.hidden = !_WKWebView.isHidden;
125+
_webView.hidden = !_webView.isHidden;
58126
}
59127

60128
- (void)_sendMessage {
@@ -67,21 +135,36 @@ - (void)_callHandler {
67135
id data = @{ @"greetingFromObjC": @"Hi there, JS!" };
68136
[_bridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) {
69137
NSLog(@"testJavascriptHandler responded: %@", response);
70-
}];
138+
}];
139+
}
140+
141+
- (void)_WKSendMessage {
142+
[_WKBridge send:@"A string sent from ObjC to JS" responseCallback:^(id response) {
143+
NSLog(@"sendMessage got response: %@", response);
144+
}];
145+
}
146+
147+
- (void)_WKCallHandler {
148+
id data = @{ @"greetingFromObjC": @"Hi there, JS!" };
149+
[_WKBridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) {
150+
NSLog(@"testJavascriptHandler responded: %@", response);
151+
}];
71152
}
72153

73154
- (void)_createViews {
74155
NSView* contentView = _window.contentView;
156+
// WebView
75157
_webView = [[WebView alloc] initWithFrame:contentView.frame];
76158
[_webView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)];
159+
_webView.hidden = YES;
160+
161+
// WKWebView
162+
_WKWebView = [[WKWebView alloc] initWithFrame:contentView.frame];
163+
[_WKWebView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)];
164+
165+
[contentView addSubview:_WKWebView];
77166
[contentView addSubview:_webView];
78167
}
79168

80-
- (void)_loadPage {
81-
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
82-
NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
83-
[[_webView mainFrame] loadHTMLString:html baseURL:nil];
84-
}
85-
86169

87170
@end

Example Apps/ExampleApp-OSX/ExampleApp-OSX-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<key>CFBundleIconFile</key>
1010
<string></string>
1111
<key>CFBundleIdentifier</key>
12-
<string>WebViewJavascriptBridge.${PRODUCT_NAME:rfc1034identifier}</string>
12+
<string>WebViewJavascriptBridge.$(PRODUCT_NAME:rfc1034identifier)</string>
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>

Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0E4E9D4C1A101E0B00043087 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8082DC19EDD98700479452 /* WebKit.framework */; };
11+
0E50601C1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */; };
12+
0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */; };
13+
0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */; };
1014
2C1562B5176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 2C1562B4176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt */; };
1115
2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */; };
12-
2C45CA2C1884AD520002A4E2 /* ExampleAppViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C45CA2B1884AD520002A4E2 /* ExampleAppViewController.m */; };
16+
2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */; };
1317
2CA045BF17117439006DEE8B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2CA045B717117439006DEE8B /* InfoPlist.strings */; };
1418
2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */; };
1519
2CA045C317117439006DEE8B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BE17117439006DEE8B /* main.m */; };
@@ -21,11 +25,18 @@
2125
/* End PBXBuildFile section */
2226

2327
/* Begin PBXFileReference section */
28+
0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridgeBase.m; sourceTree = "<group>"; };
29+
0E50601D1A01B44C000BEEEA /* WebViewJavascriptBridgeBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridgeBase.h; sourceTree = "<group>"; };
30+
0E8082D919EDC32300479452 /* WKWebViewJavascriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewJavascriptBridge.h; sourceTree = "<group>"; };
31+
0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKWebViewJavascriptBridge.m; sourceTree = "<group>"; };
32+
0E8082DC19EDD98700479452 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
33+
0ECB01421A0EE1BA0037FF4E /* ExampleWKWebViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExampleWKWebViewController.h; sourceTree = "<group>"; };
34+
0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleWKWebViewController.m; sourceTree = "<group>"; };
2435
2C1562A8176B9F6200B4AE50 /* WebViewJavascriptBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge.h; sourceTree = "<group>"; };
2536
2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = "<group>"; };
2637
2C1562B4176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebViewJavascriptBridge.js.txt; sourceTree = "<group>"; };
27-
2C45CA2A1884AD520002A4E2 /* ExampleAppViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleAppViewController.h; sourceTree = "<group>"; };
28-
2C45CA2B1884AD520002A4E2 /* ExampleAppViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleAppViewController.m; sourceTree = "<group>"; };
38+
2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleUIWebViewController.h; sourceTree = "<group>"; };
39+
2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleUIWebViewController.m; sourceTree = "<group>"; };
2940
2CA045B817117439006DEE8B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3041
2CA045B917117439006DEE8B /* ExampleApp-iOS-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ExampleApp-iOS-Info.plist"; sourceTree = "<group>"; };
3142
2CA045BA17117439006DEE8B /* ExampleApp-iOS-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ExampleApp-iOS-Prefix.pch"; sourceTree = "<group>"; };
@@ -45,6 +56,7 @@
4556
isa = PBXFrameworksBuildPhase;
4657
buildActionMask = 2147483647;
4758
files = (
59+
0E4E9D4C1A101E0B00043087 /* WebKit.framework in Frameworks */,
4860
2CEB3EC01602563600548120 /* UIKit.framework in Frameworks */,
4961
2CEB3EC21602563600548120 /* Foundation.framework in Frameworks */,
5062
2CEB3EC41602563600548120 /* CoreGraphics.framework in Frameworks */,
@@ -60,6 +72,10 @@
6072
2C1562B4176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt */,
6173
2C1562A8176B9F6200B4AE50 /* WebViewJavascriptBridge.h */,
6274
2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */,
75+
0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */,
76+
0E8082D919EDC32300479452 /* WKWebViewJavascriptBridge.h */,
77+
0E50601B1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m */,
78+
0E50601D1A01B44C000BEEEA /* WebViewJavascriptBridgeBase.h */,
6379
);
6480
name = WebViewJavascriptBridge;
6581
path = ../../WebViewJavascriptBridge;
@@ -71,8 +87,10 @@
7187
2CA0465B1711AC8D006DEE8B /* ExampleApp.html */,
7288
2CA045BC17117439006DEE8B /* ExampleAppDelegate.h */,
7389
2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */,
74-
2C45CA2A1884AD520002A4E2 /* ExampleAppViewController.h */,
75-
2C45CA2B1884AD520002A4E2 /* ExampleAppViewController.m */,
90+
2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */,
91+
2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */,
92+
0ECB01421A0EE1BA0037FF4E /* ExampleWKWebViewController.h */,
93+
0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */,
7694
2C1562A7176B9F5400B4AE50 /* WebViewJavascriptBridge */,
7795
2CA046211711A94E006DEE8B /* Supporting Files */,
7896
);
@@ -111,6 +129,7 @@
111129
2CEB3EBE1602563600548120 /* Frameworks */ = {
112130
isa = PBXGroup;
113131
children = (
132+
0E8082DC19EDD98700479452 /* WebKit.framework */,
114133
2CEB3EBF1602563600548120 /* UIKit.framework */,
115134
2CEB3EC11602563600548120 /* Foundation.framework */,
116135
2CEB3EC31602563600548120 /* CoreGraphics.framework */,
@@ -184,8 +203,11 @@
184203
buildActionMask = 2147483647;
185204
files = (
186205
2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */,
187-
2C45CA2C1884AD520002A4E2 /* ExampleAppViewController.m in Sources */,
206+
0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */,
207+
2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */,
208+
0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */,
188209
2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */,
210+
0E50601C1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m in Sources */,
189211
2CA045C317117439006DEE8B /* main.m in Sources */,
190212
);
191213
runOnlyForDeploymentPostprocessing = 0;
@@ -258,6 +280,7 @@
258280
GCC_PRECOMPILE_PREFIX_HEADER = YES;
259281
GCC_PREFIX_HEADER = "ExampleApp-iOS/ExampleApp-iOS-Prefix.pch";
260282
INFOPLIST_FILE = "ExampleApp-iOS/ExampleApp-iOS-Info.plist";
283+
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
261284
PRODUCT_NAME = "ExampleApp-iOS";
262285
WRAPPER_EXTENSION = app;
263286
};
@@ -269,6 +292,7 @@
269292
GCC_PRECOMPILE_PREFIX_HEADER = YES;
270293
GCC_PREFIX_HEADER = "ExampleApp-iOS/ExampleApp-iOS-Prefix.pch";
271294
INFOPLIST_FILE = "ExampleApp-iOS/ExampleApp-iOS-Info.plist";
295+
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
272296
PRODUCT_NAME = "ExampleApp-iOS";
273297
WRAPPER_EXTENSION = app;
274298
};

Example Apps/ExampleApp-iOS/ExampleAppDelegate.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#import "ExampleAppDelegate.h"
2-
#import "ExampleAppViewController.h"
2+
#import "ExampleUIWebViewController.h"
3+
#import "ExampleWKWebViewController.h"
34

45
@implementation ExampleAppDelegate
56

67
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
8+
9+
// 1. Create the UIWebView example
10+
ExampleUIWebViewController* UIWebViewExampleController = [[ExampleUIWebViewController alloc] init];
11+
UIWebViewExampleController.tabBarItem.title = @"UIWebView";
12+
13+
// 2. Create the tab footer and add the UIWebView example
14+
UITabBarController *tabBarController = [[UITabBarController alloc] init];
15+
[tabBarController addChildViewController:UIWebViewExampleController];
16+
17+
// 3. Create the WKWebView example for devices >= iOS 8
18+
if([WKWebView class]) {
19+
ExampleWKWebViewController* WKWebViewExampleController = [[ExampleWKWebViewController alloc] init];
20+
WKWebViewExampleController.tabBarItem.title = @"WKWebView";
21+
[tabBarController addChildViewController:WKWebViewExampleController];
22+
}
23+
724
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
8-
self.window.rootViewController = [ExampleAppViewController new];
25+
self.window.rootViewController = tabBarController;
926
[self.window makeKeyAndVisible];
1027
return YES;
1128
}

0 commit comments

Comments
 (0)