Skip to content

Commit 44ead0f

Browse files
authored
fix(ios): Remove deprecation warnings and old code (apache#1031)
* remove restoring status bar style code
1 parent 31860cf commit 44ead0f

File tree

1 file changed

+32
-117
lines changed

1 file changed

+32
-117
lines changed

src/ios/CDVWKInAppBrowser.m

Lines changed: 32 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one
1919

2020
#import "CDVWKInAppBrowser.h"
2121
#import <Cordova/NSDictionary+CordovaPreferences.h>
22-
23-
#if __has_include(<Cordova/CDVWebViewProcessPoolFactory.h>) // Cordova-iOS >=6
24-
#import <Cordova/CDVWebViewProcessPoolFactory.h>
25-
#elif __has_include("CDVWKProcessPoolFactory.h") // Cordova-iOS <6 with WKWebView plugin
26-
#import "CDVWKProcessPoolFactory.h"
27-
#endif
28-
22+
#import <Cordova/CDVWebViewProcessPoolFactory.h>
2923
#import <Cordova/CDVPluginResult.h>
3024

3125
#define kInAppBrowserTargetSelf @"_self"
@@ -43,11 +37,6 @@ Licensed to the Apache Software Foundation (ASF) under one
4337

4438
#pragma mark CDVWKInAppBrowser
4539

46-
@interface CDVWKInAppBrowser () {
47-
NSInteger _previousStatusBarStyle;
48-
}
49-
@end
50-
5140
@implementation CDVWKInAppBrowser
5241

5342
static CDVWKInAppBrowser* instance = nil;
@@ -59,7 +48,6 @@ + (id) getInstance{
5948
- (void)pluginInitialize
6049
{
6150
instance = self;
62-
_previousStatusBarStyle = -1;
6351
_callbackIdPattern = nil;
6452
_beforeload = @"";
6553
_waitForBeforeload = NO;
@@ -140,64 +128,27 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
140128
}
141129

142130
if (browserOptions.clearcache) {
143-
bool isAtLeastiOS11 = false;
144-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
145-
if (@available(iOS 11.0, *)) {
146-
isAtLeastiOS11 = true;
147-
}
148-
#endif
149-
150-
if(isAtLeastiOS11){
151-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
152-
// Deletes all cookies
153-
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
154-
[cookieStore getAllCookies:^(NSArray* cookies) {
155-
NSHTTPCookie* cookie;
156-
for(cookie in cookies){
157-
[cookieStore deleteCookie:cookie completionHandler:nil];
158-
}
159-
}];
160-
#endif
161-
}else{
162-
// https://stackoverflow.com/a/31803708/777265
163-
// Only deletes domain cookies (not session cookies)
164-
[dataStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]
165-
completionHandler:^(NSArray<WKWebsiteDataRecord *> * __nonnull records) {
166-
for (WKWebsiteDataRecord *record in records){
167-
NSSet<NSString*>* dataTypes = record.dataTypes;
168-
if([dataTypes containsObject:WKWebsiteDataTypeCookies]){
169-
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypes
170-
forDataRecords:@[record]
171-
completionHandler:^{}];
172-
}
173-
}
174-
}];
175-
}
131+
// Deletes all cookies
132+
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
133+
[cookieStore getAllCookies:^(NSArray* cookies) {
134+
NSHTTPCookie* cookie;
135+
for(cookie in cookies){
136+
[cookieStore deleteCookie:cookie completionHandler:nil];
137+
}
138+
}];
176139
}
177140

178141
if (browserOptions.clearsessioncache) {
179-
bool isAtLeastiOS11 = false;
180-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
181-
if (@available(iOS 11.0, *)) {
182-
isAtLeastiOS11 = true;
183-
}
184-
#endif
185-
if (isAtLeastiOS11) {
186-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
187-
// Deletes session cookies
188-
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
189-
[cookieStore getAllCookies:^(NSArray* cookies) {
190-
NSHTTPCookie* cookie;
191-
for(cookie in cookies){
192-
if(cookie.sessionOnly){
193-
[cookieStore deleteCookie:cookie completionHandler:nil];
194-
}
142+
// Deletes session cookies
143+
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
144+
[cookieStore getAllCookies:^(NSArray* cookies) {
145+
NSHTTPCookie* cookie;
146+
for(cookie in cookies){
147+
if(cookie.sessionOnly){
148+
[cookieStore deleteCookie:cookie completionHandler:nil];
195149
}
196-
}];
197-
#endif
198-
}else{
199-
NSLog(@"clearsessioncache not available below iOS 11.0");
200-
}
150+
}
151+
}];
201152
}
202153

203154
if (self.inAppBrowserViewController == nil) {
@@ -279,14 +230,6 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
279230
NSLog(@"Tried to show IAB after it was closed.");
280231
return;
281232
}
282-
if (_previousStatusBarStyle != -1) {
283-
NSLog(@"Tried to show IAB while already shown");
284-
return;
285-
}
286-
287-
if(!initHidden){
288-
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
289-
}
290233

291234
__block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc]
292235
initWithRootViewController:self.inAppBrowserViewController];
@@ -334,17 +277,10 @@ - (void)hide:(CDVInvokedUrlCommand*)command
334277

335278

336279
}
337-
if (_previousStatusBarStyle == -1) {
338-
NSLog(@"Tried to hide IAB while already hidden");
339-
return;
340-
}
341-
342-
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
343280

344281
// Run later to avoid the "took a long time" log message.
345282
dispatch_async(dispatch_get_main_queue(), ^{
346283
if (self.inAppBrowserViewController != nil) {
347-
_previousStatusBarStyle = -1;
348284
[self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
349285
}
350286
});
@@ -354,16 +290,17 @@ - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
354290
{
355291
NSURLRequest* request = [NSURLRequest requestWithURL:url];
356292
// the webview engine itself will filter for this according to <allow-navigation> policy
357-
// in config.xml for cordova-ios-4.0
293+
// in config.xml
358294
[self.webViewEngine loadRequest:request];
359295
}
360296

361297
- (void)openInSystem:(NSURL*)url
362298
{
363-
if ([[UIApplication sharedApplication] openURL:url] == NO) {
364-
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
365-
[[UIApplication sharedApplication] openURL:url];
366-
}
299+
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
300+
if (!success) {
301+
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
302+
}
303+
}];
367304
}
368305

369306
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
@@ -682,15 +619,6 @@ - (void)browserExit
682619
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
683620
self->tmpWindow.hidden = YES;
684621
self->tmpWindow = nil;
685-
686-
if (IsAtLeastiOSVersion(@"7.0")) {
687-
if (_previousStatusBarStyle != -1) {
688-
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];
689-
690-
}
691-
}
692-
693-
_previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar to stay black on ios7
694622
}
695623

696624
@end //CDVWKInAppBrowser
@@ -752,15 +680,11 @@ - (void)createViews
752680

753681
//WKWebView options
754682
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
755-
if (IsAtLeastiOSVersion(@"10.0")) {
756-
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
757-
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
758-
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
759-
}else{
760-
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
761-
}
762-
}else{ // iOS 9
763-
configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction;
683+
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
684+
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
685+
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
686+
}else{
687+
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
764688
}
765689

766690
if (@available(iOS 13.0, *)) {
@@ -813,11 +737,7 @@ - (void)createViews
813737
self.webView.allowsLinkPreview = NO;
814738
self.webView.allowsBackForwardNavigationGestures = NO;
815739

816-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
817-
if (@available(iOS 11.0, *)) {
818-
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
819-
}
820-
#endif
740+
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
821741

822742
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
823743
self.spinner.alpha = 1.000;
@@ -947,7 +867,7 @@ - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) b
947867
// 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)
948868
self.closeButton = nil;
949869
// Initialize with title if title is set, otherwise the title will be 'Done' localized
950-
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
870+
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
951871
self.closeButton.enabled = YES;
952872
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
953873
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
11481068
[super viewWillAppear:animated];
11491069
}
11501070

1151-
//
1152-
// On iOS 7 the status bar is part of the view's dimensions, therefore it's height has to be taken into account.
1153-
// The height of it could be hardcoded as 20 pixels, but that would assume that the upcoming releases of iOS won't
1154-
// change that value.
1155-
//
11561071
- (float) getStatusBarOffset {
1157-
return (float) IsAtLeastiOSVersion(@"7.0") ? [[UIApplication sharedApplication] statusBarFrame].size.height : 0.0;
1072+
return (float) [[UIApplication sharedApplication] statusBarFrame].size.height;
11581073
}
11591074

11601075
- (void) rePositionViews {

0 commit comments

Comments
 (0)