diff --git a/Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj b/Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj index 324a5b06..397ad111 100644 --- a/Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj +++ b/Example Apps/ExampleApp-iOS.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */; }; 2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */; }; 2C3E7C461C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C3E7C451C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m */; }; - 2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */; }; 2CA045BF17117439006DEE8B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2CA045B717117439006DEE8B /* InfoPlist.strings */; }; 2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */; }; 2CA045C317117439006DEE8B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA045BE17117439006DEE8B /* main.m */; }; @@ -34,8 +33,6 @@ 2C1562A9176B9F6200B4AE50 /* WebViewJavascriptBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge.m; sourceTree = ""; }; 2C3E7C441C5A890A00A1E322 /* WebViewJavascriptBridge_JS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewJavascriptBridge_JS.h; sourceTree = ""; }; 2C3E7C451C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewJavascriptBridge_JS.m; sourceTree = ""; }; - 2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleUIWebViewController.h; sourceTree = ""; }; - 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleUIWebViewController.m; sourceTree = ""; }; 2CA045B817117439006DEE8B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 2CA045B917117439006DEE8B /* ExampleApp-iOS-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ExampleApp-iOS-Info.plist"; sourceTree = ""; }; 2CA045BA17117439006DEE8B /* ExampleApp-iOS-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ExampleApp-iOS-Prefix.pch"; sourceTree = ""; }; @@ -85,8 +82,6 @@ 2CA0465B1711AC8D006DEE8B /* ExampleApp.html */, 2CA045BC17117439006DEE8B /* ExampleAppDelegate.h */, 2CA045BD17117439006DEE8B /* ExampleAppDelegate.m */, - 2C45CA2A1884AD520002A4E2 /* ExampleUIWebViewController.h */, - 2C45CA2B1884AD520002A4E2 /* ExampleUIWebViewController.m */, 0ECB01421A0EE1BA0037FF4E /* ExampleWKWebViewController.h */, 0ECB01431A0EE1F20037FF4E /* ExampleWKWebViewController.m */, 2C1562A7176B9F5400B4AE50 /* WebViewJavascriptBridge */, @@ -169,7 +164,7 @@ 2CEB3EB21602563600548120 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0810; + LastUpgradeCheck = 1130; ORGANIZATIONNAME = "Marcus Westin"; TargetAttributes = { 2CEB3EBA1602563600548120 = { @@ -179,10 +174,11 @@ }; buildConfigurationList = 2CEB3EB51602563600548120 /* Build configuration list for PBXProject "ExampleApp-iOS" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 2CEB3EB01602563600548120; productRefGroup = 2CEB3EBC1602563600548120 /* Products */; @@ -215,7 +211,6 @@ 2C3E7C461C5A890A00A1E322 /* WebViewJavascriptBridge_JS.m in Sources */, 2C1562C0176BA63500B4AE50 /* WebViewJavascriptBridge.m in Sources */, 0E8082DB19EDC32300479452 /* WKWebViewJavascriptBridge.m in Sources */, - 2C45CA2C1884AD520002A4E2 /* ExampleUIWebViewController.m in Sources */, 0ECB01441A0EE1F20037FF4E /* ExampleWKWebViewController.m in Sources */, 2CA045C217117439006DEE8B /* ExampleAppDelegate.m in Sources */, 0E50601C1A01B442000BEEEA /* WebViewJavascriptBridgeBase.m in Sources */, @@ -241,15 +236,24 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -282,15 +286,24 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/Example Apps/ExampleApp-iOS/ExampleAppDelegate.m b/Example Apps/ExampleApp-iOS/ExampleAppDelegate.m index ff9f5bef..5f80e5c9 100644 --- a/Example Apps/ExampleApp-iOS/ExampleAppDelegate.m +++ b/Example Apps/ExampleApp-iOS/ExampleAppDelegate.m @@ -1,20 +1,14 @@ #import "ExampleAppDelegate.h" -#import "ExampleUIWebViewController.h" #import "ExampleWKWebViewController.h" @implementation ExampleAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // 1. Create the UIWebView example - ExampleUIWebViewController* UIWebViewExampleController = [[ExampleUIWebViewController alloc] init]; - UIWebViewExampleController.tabBarItem.title = @"UIWebView"; - - // 2. Create the tab footer and add the UIWebView example + // 1. Create the tab footer UITabBarController *tabBarController = [[UITabBarController alloc] init]; - [tabBarController addChildViewController:UIWebViewExampleController]; - - // 3. Create the WKWebView example for devices >= iOS 8 + + // 2. Create the WKWebView example for devices >= iOS 8 if([WKWebView class]) { ExampleWKWebViewController* WKWebViewExampleController = [[ExampleWKWebViewController alloc] init]; WKWebViewExampleController.tabBarItem.title = @"WKWebView"; diff --git a/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.h b/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.h deleted file mode 100644 index 71364e80..00000000 --- a/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// ExampleUIWebViewController.h -// ExampleApp-iOS -// -// Created by Marcus Westin on 1/13/14. -// Copyright (c) 2014 Marcus Westin. All rights reserved. -// - -#import - -@interface ExampleUIWebViewController : UINavigationController - -@end \ No newline at end of file diff --git a/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.m b/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.m deleted file mode 100644 index f988a014..00000000 --- a/Example Apps/ExampleApp-iOS/ExampleUIWebViewController.m +++ /dev/null @@ -1,90 +0,0 @@ -// -// ExampleUIWebViewController.m -// ExampleApp-iOS -// -// Created by Marcus Westin on 1/13/14. -// Copyright (c) 2014 Marcus Westin. All rights reserved. -// - -#import "ExampleUIWebViewController.h" -#import "WebViewJavascriptBridge.h" - -@interface ExampleUIWebViewController () -@property WebViewJavascriptBridge* bridge; -@end - -@implementation ExampleUIWebViewController - -- (void)viewWillAppear:(BOOL)animated { - if (_bridge) { return; } - - UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; - [self.view addSubview:webView]; - - [WebViewJavascriptBridge enableLogging]; - - _bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; - [_bridge setWebViewDelegate:self]; - - [_bridge registerHandler:@"testObjcCallback" handler:^(id data, WVJBResponseCallback responseCallback) { - NSLog(@"testObjcCallback called: %@", data); - responseCallback(@"Response from testObjcCallback"); - }]; - - [_bridge callHandler:@"testJavascriptHandler" data:@{ @"foo":@"before ready" }]; - - [self renderButtons:webView]; - [self loadExamplePage:webView]; -} - -- (void)webViewDidStartLoad:(UIWebView *)webView { - NSLog(@"webViewDidStartLoad"); -} - -- (void)webViewDidFinishLoad:(UIWebView *)webView { - NSLog(@"webViewDidFinishLoad"); -} - -- (void)renderButtons:(UIWebView*)webView { - UIFont* font = [UIFont fontWithName:@"HelveticaNeue" size:11.0]; - - UIButton *callbackButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [callbackButton setTitle:@"Call handler" forState:UIControlStateNormal]; - [callbackButton addTarget:self action:@selector(callHandler:) forControlEvents:UIControlEventTouchUpInside]; - [self.view insertSubview:callbackButton aboveSubview:webView]; - callbackButton.frame = CGRectMake(0, 400, 100, 35); - callbackButton.titleLabel.font = font; - - UIButton* reloadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [reloadButton setTitle:@"Reload webview" forState:UIControlStateNormal]; - [reloadButton addTarget:webView action:@selector(reload) forControlEvents:UIControlEventTouchUpInside]; - [self.view insertSubview:reloadButton aboveSubview:webView]; - reloadButton.frame = CGRectMake(90, 400, 100, 35); - reloadButton.titleLabel.font = font; - - UIButton* safetyTimeoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [safetyTimeoutButton setTitle:@"Disable safety timeout" forState:UIControlStateNormal]; - [safetyTimeoutButton addTarget:self action:@selector(disableSafetyTimeout) forControlEvents:UIControlEventTouchUpInside]; - [self.view insertSubview:safetyTimeoutButton aboveSubview:webView]; - safetyTimeoutButton.frame = CGRectMake(190, 400, 120, 35); - safetyTimeoutButton.titleLabel.font = font; -} - -- (void)disableSafetyTimeout { - [self.bridge disableJavscriptAlertBoxSafetyTimeout]; -} - -- (void)callHandler:(id)sender { - id data = @{ @"greetingFromObjC": @"Hi there, JS!" }; - [_bridge callHandler:@"testJavascriptHandler" data:data responseCallback:^(id response) { - NSLog(@"testJavascriptHandler responded: %@", response); - }]; -} - -- (void)loadExamplePage:(UIWebView*)webView { - NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"]; - NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; - NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; - [webView loadHTMLString:appHtml baseURL:baseURL]; -} -@end diff --git a/README.md b/README.md index fb14d2de..e40e6ed7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ WebViewJavascriptBridge [![Circle CI](https://img.shields.io/circleci/project/github/marcuswestin/WebViewJavascriptBridge.svg)](https://circleci.com/gh/marcuswestin/WebViewJavascriptBridge) -An iOS/OSX bridge for sending messages between Obj-C and JavaScript in WKWebViews, UIWebViews & WebViews. +An iOS/OSX bridge for sending messages between Obj-C and JavaScript in WKWebViews & WebViews. Migration Guide --------------- @@ -37,7 +37,7 @@ Installation (iOS & OSX) Add this to your [podfile](https://guides.cocoapods.org/using/getting-started.html) and run `pod install` to install: ```ruby -pod 'WebViewJavascriptBridge', '~> 6.0' +pod 'WebViewJavascriptBridge', '~> 7.0' ``` ### Manual installation @@ -68,7 +68,7 @@ Usage @property WebViewJavascriptBridge* bridge; ``` -2) Instantiate WebViewJavascriptBridge with a WKWebView, UIWebView (iOS) or WebView (OSX): +2) Instantiate WebViewJavascriptBridge with a WKWebView (iOS) or WebView (OSX): ```objc self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView]; diff --git a/Tests/WebViewJavascriptBridge.xcodeproj/project.pbxproj b/Tests/WebViewJavascriptBridge.xcodeproj/project.pbxproj index 763eff7c..97f4aa42 100644 --- a/Tests/WebViewJavascriptBridge.xcodeproj/project.pbxproj +++ b/Tests/WebViewJavascriptBridge.xcodeproj/project.pbxproj @@ -80,8 +80,8 @@ isa = PBXGroup; children = ( 2C3E7C5B1C5A928700A1E322 /* WebViewJavascriptBridge.h */, - 2C3E7C5C1C5A928700A1E322 /* WebViewJavascriptBridge.m */, 2C3E7C5D1C5A928700A1E322 /* WebViewJavascriptBridge_JS.h */, + 2C3E7C5C1C5A928700A1E322 /* WebViewJavascriptBridge.m */, 2C3E7C5E1C5A928700A1E322 /* WebViewJavascriptBridge_JS.m */, 2C3E7C5F1C5A928700A1E322 /* WebViewJavascriptBridgeBase.h */, 2C3E7C601C5A928700A1E322 /* WebViewJavascriptBridgeBase.m */, @@ -223,6 +223,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); diff --git a/Tests/WebViewJavascriptBridgeTests/BridgeTests.m b/Tests/WebViewJavascriptBridgeTests/BridgeTests.m index 06a139ea..2ffc4a9e 100644 --- a/Tests/WebViewJavascriptBridgeTests/BridgeTests.m +++ b/Tests/WebViewJavascriptBridgeTests/BridgeTests.m @@ -15,12 +15,11 @@ @interface BridgeTests : XCTestCase @end -@interface TestWebPageLoadDelegate : NSObject +@interface TestWebPageLoadDelegate : NSObject @property XCTestExpectation* expectation; @end @implementation BridgeTests { - UIWebView *_uiWebView; WKWebView *_wkWebView; NSMutableArray* _retains; } @@ -31,9 +30,6 @@ - (void)setUp { UIViewController *rootVC = [[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] rootViewController]; CGRect frame = rootVC.view.bounds; frame.size.height /= 2; - _uiWebView = [[UIWebView alloc] initWithFrame:frame]; - _uiWebView.backgroundColor = [UIColor blueColor]; - [rootVC.view addSubview:_uiWebView]; frame.origin.y += frame.size.height; _wkWebView = [[WKWebView alloc] initWithFrame:frame]; _wkWebView.backgroundColor = [UIColor redColor]; @@ -44,7 +40,6 @@ - (void)setUp { - (void)tearDown { [super tearDown]; - [_uiWebView removeFromSuperview]; [_wkWebView removeFromSuperview]; } @@ -56,13 +51,12 @@ - (WebViewJavascriptBridge*)bridgeForWebView:(id)webView { static void loadEchoSample(id webView) { NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"echo" withExtension:@"html"]]; - [(UIWebView*)webView loadRequest:request]; + [(WKWebView*)webView loadRequest:request]; } const NSTimeInterval timeoutSec = 5; - (void)testEchoHandler { - [self classSpecificTestEchoHandler:_uiWebView]; [self classSpecificTestEchoHandler:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -79,7 +73,6 @@ - (void)classSpecificTestEchoHandler:(id)webView { } - (void)testEchoHandlerAfterSetup { - [self classSpecificTestEchoHandlerAfterSetup:_uiWebView]; [self classSpecificTestEchoHandlerAfterSetup:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -97,7 +90,6 @@ - (void)classSpecificTestEchoHandlerAfterSetup:(id)webView { } - (void)testObjectEncoding { - [self classSpecificTestObjectEncoding:_uiWebView]; [self classSpecificTestObjectEncoding:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -121,7 +113,6 @@ - (void)classSpecificTestObjectEncoding:(id)webView { } - (void)testJavascriptReceiveResponse { - [self classSpecificTestJavascriptReceiveResponse:_uiWebView]; [self classSpecificTestJavascriptReceiveResponse:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -139,7 +130,6 @@ - (void)classSpecificTestJavascriptReceiveResponse:(id)webView { } - (void)testJavascriptReceiveResponseWithoutSafetyTimeout { - [self classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:_uiWebView]; [self classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -158,7 +148,6 @@ - (void)classSpecificTestJavascriptReceiveResponseWithoutSafetyTimeout:(id)webVi } - (void)testWebpageLoad { - [self classSpecificTestWebpageLoad:_uiWebView]; [self classSpecificTestWebpageLoad:_wkWebView]; [self waitForExpectationsWithTimeout:timeoutSec handler:NULL]; } @@ -169,14 +158,11 @@ - (void)classSpecificTestWebpageLoad:(id)webView { [_retains addObject:delegate]; [bridge setWebViewDelegate:delegate]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://example.com"]]; - [(UIWebView*)webView loadRequest:request]; + [(WKWebView*)webView loadRequest:request]; } @end @implementation TestWebPageLoadDelegate -- (void)webViewDidFinishLoad:(UIWebView *)webView { - [self.expectation fulfill]; -} - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [self.expectation fulfill]; } diff --git a/WebViewJavascriptBridge.podspec b/WebViewJavascriptBridge.podspec index ee75de48..fc9ef816 100644 --- a/WebViewJavascriptBridge.podspec +++ b/WebViewJavascriptBridge.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'WebViewJavascriptBridge' - s.version = '6.0.3' - s.summary = 'An iOS & OSX bridge for sending messages between Obj-C/Swift and JavaScript in WKWebViews, UIWebViews & WebViews.' + s.version = '7.0.0' + s.summary = 'An iOS & OSX bridge for sending messages between Obj-C/Swift and JavaScript in WKWebViews & WebViews.' s.homepage = 'https://github.com/marcuswestin/WebViewJavascriptBridge' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'marcuswestin' => 'marcus.westin@gmail.com' } s.source = { :git => 'https://github.com/marcuswestin/WebViewJavascriptBridge.git', :tag => 'v'+s.version.to_s } - s.platforms = { :ios => "5.0", :osx => "" } + s.platforms = { :ios => "8.0", :osx => "" } s.requires_arc = true s.ios.source_files = 'WebViewJavascriptBridge/*.{h,m}' diff --git a/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m b/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m index 73c923db..e104c768 100644 --- a/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m +++ b/WebViewJavascriptBridge/WKWebViewJavascriptBridge.m @@ -96,7 +96,7 @@ - (void)WKFlushMessageQueue { if (error != nil) { NSLog(@"WebViewJavascriptBridge: WARNING: Error when trying to fetch data from WKWebView: %@", error); } - [_base flushMessageQueue:result]; + [self->_base flushMessageQueue:result]; }]; } diff --git a/WebViewJavascriptBridge/WebViewJavascriptBridge.h b/WebViewJavascriptBridge/WebViewJavascriptBridge.h index 1b64bb4e..167ead03 100755 --- a/WebViewJavascriptBridge/WebViewJavascriptBridge.h +++ b/WebViewJavascriptBridge/WebViewJavascriptBridge.h @@ -23,11 +23,14 @@ #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject #define WVJB_WEBVIEW_DELEGATE_INTERFACE NSObject #elif defined __IPHONE_OS_VERSION_MAX_ALLOWED - #import - #define WVJB_PLATFORM_IOS - #define WVJB_WEBVIEW_TYPE UIWebView - #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject - #define WVJB_WEBVIEW_DELEGATE_INTERFACE NSObject + #if defined supportsWKWebView + #define WVJB_PLATFORM_IOS + #define WVJB_WEBVIEW_TYPE WKWebView + #define WVJB_WEBVIEW_DELEGATE_TYPE id + #define WVJB_WEBVIEW_DELEGATE_INTERFACE NSObject + #else + // iOS unsupported configuration! + #endif #endif @interface WebViewJavascriptBridge : WVJB_WEBVIEW_DELEGATE_INTERFACE diff --git a/WebViewJavascriptBridge/WebViewJavascriptBridge.m b/WebViewJavascriptBridge/WebViewJavascriptBridge.m index e74a6e24..bcf09ffc 100755 --- a/WebViewJavascriptBridge/WebViewJavascriptBridge.m +++ b/WebViewJavascriptBridge/WebViewJavascriptBridge.m @@ -44,16 +44,23 @@ + (instancetype)bridge:(id)webView { return (WebViewJavascriptBridge*) [WKWebViewJavascriptBridge bridgeForWebView:webView]; } #endif +// NOTE: The following allows the old support for WebView (macOS 10.3-10.14 - now +// deprecated), but not support UIWebView (iOS 2.0-12.0 - now deprecated). +// We do NOT want to support UIWebView on iOS, as Apple is warning developers of +// UIWebView API usage when submitting an app to the AppStore. The thought is that +// this will soon be an error with iOS uploads in our near future. +#if defined WVJB_PLATFORM_OSX if ([webView isKindOfClass:[WVJB_WEBVIEW_TYPE class]]) { WebViewJavascriptBridge* bridge = [[self alloc] init]; [bridge _platformSpecificSetup:webView]; return bridge; } +#endif [NSException raise:@"BadWebViewType" format:@"Unknown web view type."]; return nil; } -- (void)setWebViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate { +- (void)setWebViewDelegate:(id)webViewDelegate { _webViewDelegate = webViewDelegate; } @@ -94,14 +101,21 @@ - (void)disableJavscriptAlertBoxSafetyTimeout { *****************************/ - (void)dealloc { - [self _platformSpecificDealloc]; + #if defined WVJB_PLATFORM_OSX + [self _platformSpecificDealloc]; + #endif _base = nil; _webView = nil; _webViewDelegate = nil; } - (NSString*) _evaluateJavascript:(NSString*)javascriptCommand { +#if defined WVJB_PLATFORM_OSX return [_webView stringByEvaluatingJavaScriptFromString:javascriptCommand]; +#else + // Respond with nothing on iOS, because this method isn't able to be used. + return [[NSString alloc] init]; +#endif } #if defined WVJB_PLATFORM_OSX @@ -145,67 +159,8 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary #elif defined WVJB_PLATFORM_IOS /* Platform specific internals: iOS **********************************/ - -- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView { - _webView = webView; - _webView.delegate = self; - _base = [[WebViewJavascriptBridgeBase alloc] init]; - _base.delegate = self; -} - -- (void) _platformSpecificDealloc { - _webView.delegate = nil; -} - -- (void)webViewDidFinishLoad:(UIWebView *)webView { - if (webView != _webView) { return; } - - __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { - [strongDelegate webViewDidFinishLoad:webView]; - } -} - -- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { - if (webView != _webView) { return; } - - __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { - [strongDelegate webView:webView didFailLoadWithError:error]; - } -} - -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { - if (webView != _webView) { return YES; } - - NSURL *url = [request URL]; - __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; - if ([_base isWebViewJavascriptBridgeURL:url]) { - if ([_base isBridgeLoadedURL:url]) { - [_base injectJavascriptFile]; - } else if ([_base isQueueMessageURL:url]) { - NSString *messageQueueString = [self _evaluateJavascript:[_base webViewJavascriptFetchQueyCommand]]; - [_base flushMessageQueue:messageQueueString]; - } else { - [_base logUnkownMessage:url]; - } - return NO; - } else if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { - return [strongDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; - } else { - return YES; - } -} - -- (void)webViewDidStartLoad:(UIWebView *)webView { - if (webView != _webView) { return; } - - __strong WVJB_WEBVIEW_DELEGATE_TYPE* strongDelegate = _webViewDelegate; - if (strongDelegate && [strongDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) { - [strongDelegate webViewDidStartLoad:webView]; - } -} - +/* REMOVED, since UIVebView is no longer supported by Apple. */ #endif + @end