This is an automated email from the ASF dual-hosted git repository.

niklasmerz pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/cordova-plugin-inappbrowser.git


The following commit(s) were added to refs/heads/master by this push:
     new 44ead0f  fix(ios): Remove deprecation warnings and old code (#1031)
44ead0f is described below

commit 44ead0fb3432de44a4997fae2ed6ceb29f30cb4a
Author: jcesarmobile <jcesarmob...@gmail.com>
AuthorDate: Sat Nov 4 19:45:56 2023 +0100

    fix(ios): Remove deprecation warnings and old code (#1031)
    
    * remove restoring status bar style code
---
 src/ios/CDVWKInAppBrowser.m | 149 ++++++++++----------------------------------
 1 file changed, 32 insertions(+), 117 deletions(-)

diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m
index 5cf8e15..a121fb1 100644
--- a/src/ios/CDVWKInAppBrowser.m
+++ b/src/ios/CDVWKInAppBrowser.m
@@ -19,13 +19,7 @@
 
 #import "CDVWKInAppBrowser.h"
 #import <Cordova/NSDictionary+CordovaPreferences.h>
-
-#if __has_include(<Cordova/CDVWebViewProcessPoolFactory.h>) // Cordova-iOS >=6
-  #import <Cordova/CDVWebViewProcessPoolFactory.h>
-#elif __has_include("CDVWKProcessPoolFactory.h") // Cordova-iOS <6 with 
WKWebView plugin
-  #import "CDVWKProcessPoolFactory.h"
-#endif
-
+#import <Cordova/CDVWebViewProcessPoolFactory.h>
 #import <Cordova/CDVPluginResult.h>
 
 #define    kInAppBrowserTargetSelf @"_self"
@@ -43,11 +37,6 @@
 
 #pragma mark CDVWKInAppBrowser
 
-@interface CDVWKInAppBrowser () {
-    NSInteger _previousStatusBarStyle;
-}
-@end
-
 @implementation CDVWKInAppBrowser
 
 static CDVWKInAppBrowser* instance = nil;
@@ -59,7 +48,6 @@ static CDVWKInAppBrowser* instance = nil;
 - (void)pluginInitialize
 {
     instance = self;
-    _previousStatusBarStyle = -1;
     _callbackIdPattern = nil;
     _beforeload = @"";
     _waitForBeforeload = NO;
@@ -140,64 +128,27 @@ static CDVWKInAppBrowser* instance = nil;
     }
     
     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<WKWebsiteDataRecord *> * __nonnull 
records) {
-                 for (WKWebsiteDataRecord *record  in records){
-                     NSSet<NSString*>* 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 @@ static CDVWKInAppBrowser* instance = nil;
         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 @@ static CDVWKInAppBrowser* instance = nil;
         
         
     }
-    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 @@ static CDVWKInAppBrowser* instance = nil;
 {
     NSURLRequest* request = [NSURLRequest requestWithURL:url];
     // the webview engine itself will filter for this according to 
<allow-navigation> 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 @@ static CDVWKInAppBrowser* instance = nil;
     // 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 @@ BOOL isExiting = FALSE;
     
     //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 @@ BOOL isExiting = FALSE;
     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 @@ BOOL isExiting = FALSE;
     // 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 @@ BOOL isExiting = FALSE;
     [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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to