@@ -19,13 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one
19
19
20
20
#import " CDVWKInAppBrowser.h"
21
21
#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>
29
23
#import < Cordova/CDVPluginResult.h>
30
24
31
25
#define kInAppBrowserTargetSelf @" _self"
@@ -43,11 +37,6 @@ Licensed to the Apache Software Foundation (ASF) under one
43
37
44
38
#pragma mark CDVWKInAppBrowser
45
39
46
- @interface CDVWKInAppBrowser () {
47
- NSInteger _previousStatusBarStyle;
48
- }
49
- @end
50
-
51
40
@implementation CDVWKInAppBrowser
52
41
53
42
static CDVWKInAppBrowser* instance = nil ;
@@ -59,7 +48,6 @@ + (id) getInstance{
59
48
- (void )pluginInitialize
60
49
{
61
50
instance = self;
62
- _previousStatusBarStyle = -1 ;
63
51
_callbackIdPattern = nil ;
64
52
_beforeload = @" " ;
65
53
_waitForBeforeload = NO ;
@@ -140,64 +128,27 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
140
128
}
141
129
142
130
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
+ }];
176
139
}
177
140
178
141
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 ];
195
149
}
196
- }];
197
- #endif
198
- }else {
199
- NSLog (@" clearsessioncache not available below iOS 11.0" );
200
- }
150
+ }
151
+ }];
201
152
}
202
153
203
154
if (self.inAppBrowserViewController == nil ) {
@@ -279,14 +230,6 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
279
230
NSLog (@" Tried to show IAB after it was closed." );
280
231
return ;
281
232
}
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
- }
290
233
291
234
__block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc ]
292
235
initWithRootViewController: self .inAppBrowserViewController];
@@ -334,17 +277,10 @@ - (void)hide:(CDVInvokedUrlCommand*)command
334
277
335
278
336
279
}
337
- if (_previousStatusBarStyle == -1 ) {
338
- NSLog (@" Tried to hide IAB while already hidden" );
339
- return ;
340
- }
341
-
342
- _previousStatusBarStyle = [UIApplication sharedApplication ].statusBarStyle ;
343
280
344
281
// Run later to avoid the "took a long time" log message.
345
282
dispatch_async (dispatch_get_main_queue (), ^{
346
283
if (self.inAppBrowserViewController != nil ) {
347
- _previousStatusBarStyle = -1 ;
348
284
[self .inAppBrowserViewController.presentingViewController dismissViewControllerAnimated: YES completion: nil ];
349
285
}
350
286
});
@@ -354,16 +290,17 @@ - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
354
290
{
355
291
NSURLRequest * request = [NSURLRequest requestWithURL: url];
356
292
// 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
358
294
[self .webViewEngine loadRequest: request];
359
295
}
360
296
361
297
- (void )openInSystem : (NSURL *)url
362
298
{
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
+ }];
367
304
}
368
305
369
306
- (void )loadAfterBeforeload : (CDVInvokedUrlCommand*)command
@@ -682,15 +619,6 @@ - (void)browserExit
682
619
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
683
620
self->tmpWindow .hidden = YES ;
684
621
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
694
622
}
695
623
696
624
@end // CDVWKInAppBrowser
@@ -752,15 +680,11 @@ - (void)createViews
752
680
753
681
// WKWebView options
754
682
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 ;
764
688
}
765
689
766
690
if (@available (iOS 13.0 , *)) {
@@ -813,11 +737,7 @@ - (void)createViews
813
737
self.webView .allowsLinkPreview = NO ;
814
738
self.webView .allowsBackForwardNavigationGestures = NO ;
815
739
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];
821
741
822
742
self.spinner = [[UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];
823
743
self.spinner .alpha = 1.000 ;
@@ -947,7 +867,7 @@ - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) b
947
867
// 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)
948
868
self.closeButton = nil ;
949
869
// 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 )];
951
871
self.closeButton .enabled = YES ;
952
872
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
953
873
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
1148
1068
[super viewWillAppear: animated];
1149
1069
}
1150
1070
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
- //
1156
1071
- (float ) getStatusBarOffset {
1157
- return (float ) IsAtLeastiOSVersion ( @" 7.0 " ) ? [[UIApplication sharedApplication ] statusBarFrame ].size .height : 0.0 ;
1072
+ return (float ) [[UIApplication sharedApplication ] statusBarFrame ].size .height ;
1158
1073
}
1159
1074
1160
1075
- (void ) rePositionViews {
0 commit comments