fix(ios): Remove deprecation warnings and old code (#1031)
* remove restoring status bar style code
This commit is contained in:
parent
31860cf6c3
commit
44ead0fb34
@ -19,13 +19,7 @@
|
|||||||
|
|
||||||
#import "CDVWKInAppBrowser.h"
|
#import "CDVWKInAppBrowser.h"
|
||||||
#import <Cordova/NSDictionary+CordovaPreferences.h>
|
#import <Cordova/NSDictionary+CordovaPreferences.h>
|
||||||
|
#import <Cordova/CDVWebViewProcessPoolFactory.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/CDVPluginResult.h>
|
#import <Cordova/CDVPluginResult.h>
|
||||||
|
|
||||||
#define kInAppBrowserTargetSelf @"_self"
|
#define kInAppBrowserTargetSelf @"_self"
|
||||||
@ -43,11 +37,6 @@
|
|||||||
|
|
||||||
#pragma mark CDVWKInAppBrowser
|
#pragma mark CDVWKInAppBrowser
|
||||||
|
|
||||||
@interface CDVWKInAppBrowser () {
|
|
||||||
NSInteger _previousStatusBarStyle;
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation CDVWKInAppBrowser
|
@implementation CDVWKInAppBrowser
|
||||||
|
|
||||||
static CDVWKInAppBrowser* instance = nil;
|
static CDVWKInAppBrowser* instance = nil;
|
||||||
@ -59,7 +48,6 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
- (void)pluginInitialize
|
- (void)pluginInitialize
|
||||||
{
|
{
|
||||||
instance = self;
|
instance = self;
|
||||||
_previousStatusBarStyle = -1;
|
|
||||||
_callbackIdPattern = nil;
|
_callbackIdPattern = nil;
|
||||||
_beforeload = @"";
|
_beforeload = @"";
|
||||||
_waitForBeforeload = NO;
|
_waitForBeforeload = NO;
|
||||||
@ -140,15 +128,6 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (browserOptions.clearcache) {
|
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
|
// Deletes all cookies
|
||||||
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
|
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
|
||||||
[cookieStore getAllCookies:^(NSArray* cookies) {
|
[cookieStore getAllCookies:^(NSArray* cookies) {
|
||||||
@ -157,33 +136,9 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
[cookieStore deleteCookie:cookie completionHandler:nil];
|
[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:^{}];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browserOptions.clearsessioncache) {
|
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
|
// Deletes session cookies
|
||||||
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
|
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
|
||||||
[cookieStore getAllCookies:^(NSArray* cookies) {
|
[cookieStore getAllCookies:^(NSArray* cookies) {
|
||||||
@ -194,10 +149,6 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
#endif
|
|
||||||
}else{
|
|
||||||
NSLog(@"clearsessioncache not available below iOS 11.0");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.inAppBrowserViewController == nil) {
|
if (self.inAppBrowserViewController == nil) {
|
||||||
@ -279,14 +230,6 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
NSLog(@"Tried to show IAB after it was closed.");
|
NSLog(@"Tried to show IAB after it was closed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_previousStatusBarStyle != -1) {
|
|
||||||
NSLog(@"Tried to show IAB while already shown");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!initHidden){
|
|
||||||
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
__block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc]
|
__block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc]
|
||||||
initWithRootViewController:self.inAppBrowserViewController];
|
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.
|
// Run later to avoid the "took a long time" log message.
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
if (self.inAppBrowserViewController != nil) {
|
if (self.inAppBrowserViewController != nil) {
|
||||||
_previousStatusBarStyle = -1;
|
|
||||||
[self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
[self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -354,16 +290,17 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
{
|
{
|
||||||
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
||||||
// the webview engine itself will filter for this according to <allow-navigation> policy
|
// 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];
|
[self.webViewEngine loadRequest:request];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)openInSystem:(NSURL*)url
|
- (void)openInSystem:(NSURL*)url
|
||||||
{
|
{
|
||||||
if ([[UIApplication sharedApplication] openURL:url] == NO) {
|
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
|
||||||
|
if (!success) {
|
||||||
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
|
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
|
||||||
[[UIApplication sharedApplication] openURL:url];
|
|
||||||
}
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
|
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
|
||||||
@ -682,15 +619,6 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
|
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
|
||||||
self->tmpWindow.hidden = YES;
|
self->tmpWindow.hidden = YES;
|
||||||
self->tmpWindow = nil;
|
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
|
@end //CDVWKInAppBrowser
|
||||||
@ -752,16 +680,12 @@ BOOL isExiting = FALSE;
|
|||||||
|
|
||||||
//WKWebView options
|
//WKWebView options
|
||||||
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
|
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
|
||||||
if (IsAtLeastiOSVersion(@"10.0")) {
|
|
||||||
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
|
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
|
||||||
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
|
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
|
||||||
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
|
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
|
||||||
}else{
|
}else{
|
||||||
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
|
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
|
||||||
}
|
}
|
||||||
}else{ // iOS 9
|
|
||||||
configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@available(iOS 13.0, *)) {
|
if (@available(iOS 13.0, *)) {
|
||||||
NSString *contentMode = [self settingForKey:@"PreferredContentMode"];
|
NSString *contentMode = [self settingForKey:@"PreferredContentMode"];
|
||||||
@ -813,11 +737,7 @@ BOOL isExiting = FALSE;
|
|||||||
self.webView.allowsLinkPreview = NO;
|
self.webView.allowsLinkPreview = NO;
|
||||||
self.webView.allowsBackForwardNavigationGestures = NO;
|
self.webView.allowsBackForwardNavigationGestures = NO;
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
|
|
||||||
if (@available(iOS 11.0, *)) {
|
|
||||||
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
|
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||||
self.spinner.alpha = 1.000;
|
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)
|
// 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;
|
self.closeButton = nil;
|
||||||
// Initialize with title if title is set, otherwise the title will be 'Done' localized
|
// 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;
|
self.closeButton.enabled = YES;
|
||||||
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
|
// 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];
|
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];
|
[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 {
|
- (float) getStatusBarOffset {
|
||||||
return (float) IsAtLeastiOSVersion(@"7.0") ? [[UIApplication sharedApplication] statusBarFrame].size.height : 0.0;
|
return (float) [[UIApplication sharedApplication] statusBarFrame].size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) rePositionViews {
|
- (void) rePositionViews {
|
||||||
|
Loading…
Reference in New Issue
Block a user