diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index 5cf8e1570..a121fb19d 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -19,13 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one #import "CDVWKInAppBrowser.h" #import - -#if __has_include() // Cordova-iOS >=6 - #import -#elif __has_include("CDVWKProcessPoolFactory.h") // Cordova-iOS <6 with WKWebView plugin - #import "CDVWKProcessPoolFactory.h" -#endif - +#import #import #define kInAppBrowserTargetSelf @"_self" @@ -43,11 +37,6 @@ Licensed to the Apache Software Foundation (ASF) under one #pragma mark CDVWKInAppBrowser -@interface CDVWKInAppBrowser () { - NSInteger _previousStatusBarStyle; -} -@end - @implementation CDVWKInAppBrowser static CDVWKInAppBrowser* instance = nil; @@ -59,7 +48,6 @@ + (id) getInstance{ - (void)pluginInitialize { instance = self; - _previousStatusBarStyle = -1; _callbackIdPattern = nil; _beforeload = @""; _waitForBeforeload = NO; @@ -140,64 +128,27 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options } if (browserOptions.clearcache) { - bool isAtLeastiOS11 = false; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - if (@available(iOS 11.0, *)) { - isAtLeastiOS11 = true; - } -#endif - - if(isAtLeastiOS11){ -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - // Deletes all cookies - WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore; - [cookieStore getAllCookies:^(NSArray* cookies) { - NSHTTPCookie* cookie; - for(cookie in cookies){ - [cookieStore deleteCookie:cookie completionHandler:nil]; - } - }]; -#endif - }else{ - // https://stackoverflow.com/a/31803708/777265 - // Only deletes domain cookies (not session cookies) - [dataStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] - completionHandler:^(NSArray * __nonnull records) { - for (WKWebsiteDataRecord *record in records){ - NSSet* dataTypes = record.dataTypes; - if([dataTypes containsObject:WKWebsiteDataTypeCookies]){ - [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypes - forDataRecords:@[record] - completionHandler:^{}]; - } - } - }]; - } + // Deletes all cookies + WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore; + [cookieStore getAllCookies:^(NSArray* cookies) { + NSHTTPCookie* cookie; + for(cookie in cookies){ + [cookieStore deleteCookie:cookie completionHandler:nil]; + } + }]; } if (browserOptions.clearsessioncache) { - bool isAtLeastiOS11 = false; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - if (@available(iOS 11.0, *)) { - isAtLeastiOS11 = true; - } -#endif - if (isAtLeastiOS11) { -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - // Deletes session cookies - WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore; - [cookieStore getAllCookies:^(NSArray* cookies) { - NSHTTPCookie* cookie; - for(cookie in cookies){ - if(cookie.sessionOnly){ - [cookieStore deleteCookie:cookie completionHandler:nil]; - } + // Deletes session cookies + WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore; + [cookieStore getAllCookies:^(NSArray* cookies) { + NSHTTPCookie* cookie; + for(cookie in cookies){ + if(cookie.sessionOnly){ + [cookieStore deleteCookie:cookie completionHandler:nil]; } - }]; -#endif - }else{ - NSLog(@"clearsessioncache not available below iOS 11.0"); - } + } + }]; } if (self.inAppBrowserViewController == nil) { @@ -279,14 +230,6 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate NSLog(@"Tried to show IAB after it was closed."); return; } - if (_previousStatusBarStyle != -1) { - NSLog(@"Tried to show IAB while already shown"); - return; - } - - if(!initHidden){ - _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; - } __block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc] initWithRootViewController:self.inAppBrowserViewController]; @@ -334,17 +277,10 @@ - (void)hide:(CDVInvokedUrlCommand*)command } - if (_previousStatusBarStyle == -1) { - NSLog(@"Tried to hide IAB while already hidden"); - return; - } - - _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; // Run later to avoid the "took a long time" log message. dispatch_async(dispatch_get_main_queue(), ^{ if (self.inAppBrowserViewController != nil) { - _previousStatusBarStyle = -1; [self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } }); @@ -354,16 +290,17 @@ - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options { NSURLRequest* request = [NSURLRequest requestWithURL:url]; // the webview engine itself will filter for this according to policy - // in config.xml for cordova-ios-4.0 + // in config.xml [self.webViewEngine loadRequest:request]; } - (void)openInSystem:(NSURL*)url { - if ([[UIApplication sharedApplication] openURL:url] == NO) { - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; - [[UIApplication sharedApplication] openURL:url]; - } + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { + if (!success) { + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; + } + }]; } - (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command @@ -682,15 +619,6 @@ - (void)browserExit // Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow self->tmpWindow.hidden = YES; self->tmpWindow = nil; - - if (IsAtLeastiOSVersion(@"7.0")) { - if (_previousStatusBarStyle != -1) { - [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; - - } - } - - _previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar to stay black on ios7 } @end //CDVWKInAppBrowser @@ -752,15 +680,11 @@ - (void)createViews //WKWebView options configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback; - if (IsAtLeastiOSVersion(@"10.0")) { - configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale; - if(_browserOptions.mediaplaybackrequiresuseraction == YES){ - configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; - }else{ - configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; - } - }else{ // iOS 9 - configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction; + configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale; + if(_browserOptions.mediaplaybackrequiresuseraction == YES){ + configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll; + }else{ + configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; } if (@available(iOS 13.0, *)) { @@ -813,11 +737,7 @@ - (void)createViews self.webView.allowsLinkPreview = NO; self.webView.allowsBackForwardNavigationGestures = NO; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 - if (@available(iOS 11.0, *)) { - [self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; - } -#endif + [self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.alpha = 1.000; @@ -947,7 +867,7 @@ - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) b // but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one) self.closeButton = nil; // Initialize with title if title is set, otherwise the title will be 'Done' localized - self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)]; + self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)]; self.closeButton.enabled = YES; // If color on closebutton is requested then initialize with that that color, otherwise use initialize with default self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; @@ -1148,13 +1068,8 @@ - (void)viewWillAppear:(BOOL)animated [super viewWillAppear:animated]; } -// -// On iOS 7 the status bar is part of the view's dimensions, therefore it's height has to be taken into account. -// The height of it could be hardcoded as 20 pixels, but that would assume that the upcoming releases of iOS won't -// change that value. -// - (float) getStatusBarOffset { - return (float) IsAtLeastiOSVersion(@"7.0") ? [[UIApplication sharedApplication] statusBarFrame].size.height : 0.0; + return (float) [[UIApplication sharedApplication] statusBarFrame].size.height; } - (void) rePositionViews {