CB-8659 - Update InAppBrowser to support both cordova-ios 4.0.x and 3.x (closes #93)
diff --git a/src/ios/CDVInAppBrowser.h b/src/ios/CDVInAppBrowser.h
index c92d9b7..1ccc7b1 100644
--- a/src/ios/CDVInAppBrowser.h
+++ b/src/ios/CDVInAppBrowser.h
@@ -20,7 +20,12 @@
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVInvokedUrlCommand.h>
#import <Cordova/CDVScreenOrientationDelegate.h>
-#import <Cordova/CDVWebViewDelegate.h>
+
+#ifdef __CORDOVA_4_0_0
+ #import <Cordova/CDVUIWebViewDelegate.h>
+#else
+ #import <Cordova/CDVWebViewDelegate.h>
+#endif
@class CDVInAppBrowserViewController;
@@ -69,7 +74,13 @@
NSString* _prevUserAgent;
NSInteger _userAgentLockToken;
CDVInAppBrowserOptions *_browserOptions;
+
+#ifdef __CORDOVA_4_0_0
+ CDVUIWebViewDelegate* _webViewDelegate;
+#else
CDVWebViewDelegate* _webViewDelegate;
+#endif
+
}
@property (nonatomic, strong) IBOutlet UIWebView* webView;
diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m
index 71e214e..6d141d3 100644
--- a/src/ios/CDVInAppBrowser.m
+++ b/src/ios/CDVInAppBrowser.m
@@ -41,15 +41,10 @@
@implementation CDVInAppBrowser
-- (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView
+- (void)pluginInitialize
{
- self = [super initWithWebView:theWebView];
- if (self != nil) {
- _previousStatusBarStyle = -1;
- _callbackIdPattern = nil;
- }
-
- return self;
+ _previousStatusBarStyle = -1;
+ _callbackIdPattern = nil;
}
- (void)onReset
@@ -87,7 +82,11 @@
self.callbackId = command.callbackId;
if (url != nil) {
+#ifdef __CORDOVA_4_0_0
+ NSURL* baseUrl = [self.webViewEngine URL];
+#else
NSURL* baseUrl = [self.webView.request URL];
+#endif
NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
if ([self isSystemUrl:absoluteUrl]) {
@@ -231,7 +230,11 @@
{
if ([self.commandDelegate URLIsWhitelisted:url]) {
NSURLRequest* request = [NSURLRequest requestWithURL:url];
+#ifdef __CORDOVA_4_0_0
+ [self.webViewEngine loadRequest:request];
+#else
[self.webView loadRequest:request];
+#endif
} else { // this assumes the InAppBrowser can be excepted from the white-list
[self openInInAppBrowser:url withOptions:options];
}
@@ -462,7 +465,12 @@
_userAgent = userAgent;
_prevUserAgent = prevUserAgent;
_browserOptions = browserOptions;
+#ifdef __CORDOVA_4_0_0
+ _webViewDelegate = [[CDVUIWebViewDelegate alloc] initWithDelegate:self];
+#else
_webViewDelegate = [[CDVWebViewDelegate alloc] initWithDelegate:self];
+#endif
+
[self createViews];
}