Skip to content

Commit

Permalink
Example app dynamically includes Webkit if iOS 8
Browse files Browse the repository at this point in the history
  • Loading branch information
lokimeyburg committed Oct 15, 2014
1 parent 84bbefc commit 026a712
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
0E3214AF19EDF7CF0075E78F /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8082DC19EDD98700479452 /* WebKit.framework */; };
0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E8082DA19EDC32300479452 /* WKWebViewJavascriptBridge.m */; };
2C1562B5176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 2C1562B4176B9F8400B4AE50 /* WebViewJavascriptBridge.js.txt */; };
2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */; };
Expand Down Expand Up @@ -50,7 +49,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0E3214AF19EDF7CF0075E78F /* WebKit.framework in Frameworks */,
2CEB3EC01602563600548120 /* UIKit.framework in Frameworks */,
2CEB3EC21602563600548120 /* Foundation.framework in Frameworks */,
2CEB3EC41602563600548120 /* CoreGraphics.framework in Frameworks */,
Expand Down
8 changes: 4 additions & 4 deletions Example Apps/ExampleApp-iOS/ExampleAppViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ @implementation ExampleAppViewController
- (void)viewWillAppear:(BOOL)animated {
if (_bridge) { return; }

#if defined(__IPHONE_8_0)
WKWebView* webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
#if defined(__IPHONE_8_0)
WKWebView* webView = [[NSClassFromString(@"WKWebView") alloc] initWithFrame:self.view.bounds];
webView.navigationDelegate = self;
[self.view addSubview:webView];
[WKWebViewJavascriptBridge enableLogging];
_bridge = [WKWebViewJavascriptBridge bridgeForWebView:webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {
NSLog(@"ObjC received message from JS: %@", data);
responseCallback(@"Response for message from ObjC");
}];
#else
#else
UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:webView];
[WebViewJavascriptBridge enableLogging];
_bridge = [WebViewJavascriptBridge bridgeForWebView:webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {
NSLog(@"ObjC received message from JS: %@", data);
responseCallback(@"Response for message from ObjC");
}];
#endif
#endif



Expand Down
22 changes: 19 additions & 3 deletions Example Apps/ExampleApp-iOS/main.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#import <UIKit/UIKit.h>

#import <TargetConditionals.h>
#import <dlfcn.h>
#import "ExampleAppDelegate.h"

int main(int argc, char *argv[])
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

int main(int argc, char * argv[])
{
@autoreleasepool {
// Dynamically load WebKit if iOS version >= 8
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
#if TARGET_IPHONE_SIMULATOR
NSString *frameworkPath = [[NSProcessInfo processInfo] environment][@"DYLD_FALLBACK_FRAMEWORK_PATH"];
if (frameworkPath) {
NSString *webkitLibraryPath = [NSString pathWithComponents:@[frameworkPath, @"WebKit.framework", @"WebKit"]];
dlopen([webkitLibraryPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_LAZY);
}
#else
dlopen("/System/Library/Frameworks/WebKit.framework/WebKit", RTLD_LAZY);
#endif
}

return UIApplicationMain(argc, argv, nil, NSStringFromClass([ExampleAppDelegate class]));
}
}
}

0 comments on commit 026a712

Please sign in to comment.