Skip to content

Commit 026a712

Browse files
committed
Example app dynamically includes Webkit if iOS 8
1 parent 84bbefc commit 026a712

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

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

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

99
/* Begin PBXBuildFile section */
10-
0E3214AF19EDF7CF0075E78F /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8082DC19EDD98700479452 /* WebKit.framework */; };
1110
0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */; };
1211
2C1562B5176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 2C1562B4176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt */; };
1312
2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */; };
@@ -50,7 +49,6 @@
5049
isa = PBXFrameworksBuildPhase;
5150
buildActionMask = 2147483647;
5251
files = (
53-
0E3214AF19EDF7CF0075E78F /* WebKit.framework in Frameworks */,
5452
2CEB3EC01602563600548120 /* UIKit.framework in Frameworks */,
5553
2CEB3EC21602563600548120 /* Foundation.framework in Frameworks */,
5654
2CEB3EC41602563600548120 /* CoreGraphics.framework in Frameworks */,

Example Apps/ExampleApp-iOS/ExampleAppViewController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ @implementation ExampleAppViewController
2525
- (void)viewWillAppear:(BOOL)animated {
2626
if (_bridge) { return; }
2727

28-
#if defined(__IPHONE_8_0)
29-
WKWebView* webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
28+
#if defined(__IPHONE_8_0)
29+
WKWebView* webView = [[NSClassFromString(@"WKWebView") alloc] initWithFrame:self.view.bounds];
3030
webView.navigationDelegate = self;
3131
[self.view addSubview:webView];
3232
[WKWebViewJavascriptBridge enableLogging];
3333
_bridge = [WKWebViewJavascriptBridge bridgeForWebView:webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {
3434
NSLog(@"ObjC received message from JS: %@", data);
3535
responseCallback(@"Response for message from ObjC");
3636
}];
37-
#else
37+
#else
3838
UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
3939
[self.view addSubview:webView];
4040
[WebViewJavascriptBridge enableLogging];
4141
_bridge = [WebViewJavascriptBridge bridgeForWebView:webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {
4242
NSLog(@"ObjC received message from JS: %@", data);
4343
responseCallback(@"Response for message from ObjC");
4444
}];
45-
#endif
45+
#endif
4646

4747

4848

Example Apps/ExampleApp-iOS/main.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
#import <UIKit/UIKit.h>
2-
2+
#import <TargetConditionals.h>
3+
#import <dlfcn.h>
34
#import "ExampleAppDelegate.h"
45

5-
int main(int argc, char *argv[])
6+
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
7+
8+
int main(int argc, char * argv[])
69
{
710
@autoreleasepool {
11+
// Dynamically load WebKit if iOS version >= 8
12+
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
13+
#if TARGET_IPHONE_SIMULATOR
14+
NSString *frameworkPath = [[NSProcessInfo processInfo] environment][@"DYLD_FALLBACK_FRAMEWORK_PATH"];
15+
if (frameworkPath) {
16+
NSString *webkitLibraryPath = [NSString pathWithComponents:@[frameworkPath, @"WebKit.framework", @"WebKit"]];
17+
dlopen([webkitLibraryPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_LAZY);
18+
}
19+
#else
20+
dlopen("/System/Library/Frameworks/WebKit.framework/WebKit", RTLD_LAZY);
21+
#endif
22+
}
23+
824
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ExampleAppDelegate class]));
925
}
10-
}
26+
}

0 commit comments

Comments
 (0)