From 75cf07f48cfc14e3caac0cdbe3e0295a57ac27c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 09:21:20 +0200 Subject: [PATCH 01/21] conditionally set MODERN_WEB_VIEW_ONLY build property --- bin/templates/scripts/cordova/lib/prepare.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index a15380ed6..ffb55fcc5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -280,6 +280,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); + var modernWebViewOnly = platformConfig.getPreference('CordovaWebViewEngine', 'ios') === 'CDVWKWebViewEngine'; var project; @@ -317,6 +318,11 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion); } + if (modernWebViewOnly) { + events.emit('verbose', 'Set MODERN_WEB_VIEW_ONLY.'); + project.xcode.updateBuildProperty('MODERN_WEB_VIEW_ONLY', '1'); + } + updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); project.write(); From fe0e4b71a0a93361ed47e1675717edfe0f95cb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 09:42:49 +0200 Subject: [PATCH 02/21] set GCC_PREPROCESSOR_DEFINITIONS --- bin/templates/scripts/cordova/build.xcconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/build.xcconfig b/bin/templates/scripts/cordova/build.xcconfig index cc78c73e5..ad6814439 100644 --- a/bin/templates/scripts/cordova/build.xcconfig +++ b/bin/templates/scripts/cordova/build.xcconfig @@ -36,8 +36,10 @@ ENABLE_BITCODE = NO // (CB-9719) Set CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES to YES in build.xcconfig CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES -// (CB-10072) +// (CB-10072) SWIFT_OBJC_BRIDGING_HEADER = $(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h // (CB-11854) CODE_SIGN_ENTITLEMENTS = $(PROJECT_DIR)/$(PROJECT_NAME)/Entitlements-$(CONFIGURATION).plist + +GCC_PREPROCESSOR_DEFINITIONS = MODERN_WEB_VIEW_ONLY=$(MODERN_WEB_VIEW_ONLY) From 57b6519c17ce8928ab508425b6552f93d037c853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 09:48:30 +0200 Subject: [PATCH 03/21] have separate preference for ModernWebViewOnly --- bin/templates/scripts/cordova/lib/prepare.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index ffb55fcc5..3bb8d16c1 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -280,7 +280,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var modernWebViewOnly = platformConfig.getPreference('CordovaWebViewEngine', 'ios') === 'CDVWKWebViewEngine'; + var modernWebViewOnly = platformConfig.getPreference('ModernWebViewOnly', 'ios') === 'true'; var project; @@ -294,7 +294,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { // no build settings provided and we don't need to update build settings for launch storyboards, // then we don't need to parse and update .pbxproj file - if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) { + if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion && !modernWebViewOnly) { return Q(); } From 77f9107914a29dfa951d3c9912b80967273a98ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 10:37:34 +0200 Subject: [PATCH 04/21] conditional compilation of WebView code --- .../CDVUIWebViewEngine/CDVUIWebViewDelegate.h | 4 +++ .../CDVUIWebViewEngine/CDVUIWebViewDelegate.m | 6 +++- .../CDVUIWebViewEngine/CDVUIWebViewEngine.h | 2 ++ .../CDVUIWebViewEngine/CDVUIWebViewEngine.m | 4 +++ .../CDVUIWebViewNavigationDelegate.h | 4 +++ .../CDVUIWebViewNavigationDelegate.m | 12 ++++--- CordovaLib/Classes/Public/CDVUserAgentUtil.m | 36 +++++++++++++++++++ CordovaLib/Classes/Public/CDVViewController.m | 27 +++++++------- CordovaLib/Cordova/Cordova.h | 5 ++- 9 files changed, 78 insertions(+), 22 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h index 7db8a4ea7..a1de6bfd8 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h @@ -17,6 +17,8 @@ under the License. */ + #if !MODERN_WEB_VIEW_ONLY + #import #import @@ -39,3 +41,5 @@ - (BOOL)request:(NSURLRequest*)newRequest isEqualToRequestAfterStrippingFragments:(NSURLRequest*)originalRequest; @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m index 93fbb67cc..98a3fbca2 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m @@ -76,6 +76,8 @@ Licensed to the Apache Software Foundation (ASF) under one // TODO: Record order when page is re-navigated before the first navigation finishes. // + #if !MODERN_WEB_VIEW_ONLY + #import "CDVUIWebViewDelegate.h" // #define VerboseLog NSLog @@ -256,7 +258,7 @@ - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)re NSLog(@"%@", description); _loadCount = 0; _state = STATE_WAITING_FOR_LOAD_START; - + NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey : description}; NSError* error = [[NSError alloc] initWithDomain:@"CDVUIWebViewDelegate" code:1 userInfo:errorDictionary]; [self webView:webView didFailLoadWithError:error]; @@ -402,3 +404,5 @@ - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error } @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h index f4070092c..673ff95c6 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h @@ -22,6 +22,8 @@ @interface CDVUIWebViewEngine : CDVPlugin +#if !MODERN_WEB_VIEW_ONLY @property (nonatomic, strong, readonly) id uiWebViewDelegate; +#endif @end diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m index bbd343c15..e354e9a84 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m @@ -17,6 +17,8 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ +#if !MODERN_WEB_VIEW_ONLY + #import "CDVUIWebViewEngine.h" #import "CDVUIWebViewDelegate.h" #import "CDVUIWebViewNavigationDelegate.h" @@ -200,3 +202,5 @@ - (UIView*)webView } @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h index 9138deba8..886a347d1 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h @@ -17,6 +17,8 @@ under the License. */ + #if !MODERN_WEB_VIEW_ONLY + #import #import "CDVUIWebViewEngine.h" @@ -27,3 +29,5 @@ - (instancetype)initWithEnginePlugin:(CDVPlugin*)enginePlugin; @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m index bc56fdde0..8be2899bb 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m @@ -17,6 +17,8 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ + #if !MODERN_WEB_VIEW_ONLY + #import "CDVUIWebViewNavigationDelegate.h" #import #import @@ -94,7 +96,7 @@ - (BOOL)defaultResourcePolicyForURL:(NSURL*)url if ([url isFileURL]) { return YES; } - + return NO; } @@ -120,7 +122,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* */ BOOL anyPluginsResponded = NO; BOOL shouldAllowRequest = NO; - + for (NSString* pluginName in vc.pluginObjects) { CDVPlugin* plugin = [vc.pluginObjects objectForKey:pluginName]; SEL selector = NSSelectorFromString(@"shouldOverrideLoadWithRequest:navigationType:"); @@ -132,7 +134,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* } } } - + if (anyPluginsResponded) { return shouldAllowRequest; } @@ -146,8 +148,10 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest* } else { [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; } - + return NO; } @end + +#endif diff --git a/CordovaLib/Classes/Public/CDVUserAgentUtil.m b/CordovaLib/Classes/Public/CDVUserAgentUtil.m index 6eb591204..bca0d9de1 100644 --- a/CordovaLib/Classes/Public/CDVUserAgentUtil.m +++ b/CordovaLib/Classes/Public/CDVUserAgentUtil.m @@ -32,6 +32,38 @@ Licensed to the Apache Software Foundation (ASF) under one static NSInteger gCurrentLockToken = 0; static NSMutableArray* gPendingSetUserAgentBlocks = nil; + #if MODERN_WEB_VIEW_ONLY +@interface WKWebView(SynchronousEvaluateJavaScript) +- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script; +@end + +@implementation WKWebView(SynchronousEvaluateJavaScript) + +- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script +{ + __block NSString *resultString = nil; + __block BOOL finished = NO; + + [self evaluateJavaScript:script completionHandler:^(id result, NSError *error) { + if (error == nil) { + if (result != nil) { + resultString = [NSString stringWithFormat:@"%@", result]; + } + } else { + NSLog(@"evaluateJavaScript error : %@", error.localizedDescription); + } + finished = YES; + }]; + + while (!finished) { + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; + } + + return resultString; +} +@end +#endif + @implementation CDVUserAgentUtil + (NSString*)originalUserAgent @@ -54,7 +86,11 @@ + (NSString*)originalUserAgent BOOL cachedValueIsOld = ![systemAndLocale isEqualToString:cordovaUserAgentVersion]; if ((gOriginalUserAgent == nil) || cachedValueIsOld) { + #if MODERN_WEB_VIEW_ONLY + WKWebView* sampleWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; + #else UIWebView* sampleWebView = [[UIWebView alloc] initWithFrame:CGRectZero]; +#endif gOriginalUserAgent = [sampleWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; [userDefaults setObject:gOriginalUserAgent forKey:kCdvUserAgentKey]; diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m index 616d9ff3b..75e74add0 100644 --- a/CordovaLib/Classes/Public/CDVViewController.m +++ b/CordovaLib/Classes/Public/CDVViewController.m @@ -20,7 +20,6 @@ Licensed to the Apache Software Foundation (ASF) under one #import #import "CDV.h" #import "CDVPlugin+Private.h" -#import "CDVUIWebViewDelegate.h" #import "CDVConfigParser.h" #import "CDVUserAgentUtil.h" #import @@ -343,9 +342,9 @@ - (void)viewDidLoad } } }]; - + // ///////////////// - + NSString* bgColorString = [self.settings cordovaSettingForKey:@"BackgroundColor"]; UIColor* bgColor = [self colorFromColorString:bgColorString]; [self.webView setBackgroundColor:bgColor]; @@ -405,16 +404,16 @@ - (UIColor*)colorFromColorString:(NSString*)colorString if (!colorString) { return nil; } - + // Validate format NSError* error = NULL; NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"^(#[0-9A-F]{3}|(0x|#)([0-9A-F]{2})?[0-9A-F]{6})$" options:NSRegularExpressionCaseInsensitive error:&error]; NSUInteger countMatches = [regex numberOfMatchesInString:colorString options:0 range:NSMakeRange(0, [colorString length])]; - + if (!countMatches) { return nil; } - + // #FAB to #FFAABB if ([colorString hasPrefix:@"#"] && [colorString length] == 4) { NSString* r = [colorString substringWithRange:NSMakeRange(1, 1)]; @@ -422,22 +421,22 @@ - (UIColor*)colorFromColorString:(NSString*)colorString NSString* b = [colorString substringWithRange:NSMakeRange(3, 1)]; colorString = [NSString stringWithFormat:@"#%@%@%@%@%@%@", r, r, g, g, b, b]; } - + // #RRGGBB to 0xRRGGBB colorString = [colorString stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]; - + // 0xRRGGBB to 0xAARRGGBB if ([colorString hasPrefix:@"0x"] && [colorString length] == 8) { colorString = [@"0xFF" stringByAppendingString:[colorString substringFromIndex:2]]; } - + // 0xAARRGGBB to int unsigned colorValue = 0; NSScanner *scanner = [NSScanner scannerWithString:colorString]; if (![scanner scanHexInt:&colorValue]) { return nil; } - + // int to UIColor return [UIColor colorWithRed:((float)((colorValue & 0x00FF0000) >> 16))/255.0 green:((float)((colorValue & 0x0000FF00) >> 8))/255.0 @@ -480,9 +479,9 @@ - (BOOL)shouldAutorotate } // CB-12098 -#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 -- (NSUInteger)supportedInterfaceOrientations -#else +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 +- (NSUInteger)supportedInterfaceOrientations +#else - (UIInterfaceOrientationMask)supportedInterfaceOrientations #endif { @@ -757,7 +756,7 @@ - (void)onAppWillEnterForeground:(NSNotification*)notification [self checkAndReinitViewUrl]; // NSLog(@"%@",@"applicationWillEnterForeground"); [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resume');"]; - + if (!IsAtLeastiOSVersion(@"11.0")) { /** Clipboard fix **/ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; diff --git a/CordovaLib/Cordova/Cordova.h b/CordovaLib/Cordova/Cordova.h index 1d69468aa..8f3107709 100644 --- a/CordovaLib/Cordova/Cordova.h +++ b/CordovaLib/Cordova/Cordova.h @@ -6,9 +6,9 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -44,7 +44,6 @@ FOUNDATION_EXPORT const unsigned char CordovaVersionString[]; #import #import #import -#import #import #import #import From 618a2d1815314d014398a50a05aaad9aca771ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 11:02:57 +0200 Subject: [PATCH 05/21] renamed preference to 'WKWebViewOnly' --- bin/templates/scripts/cordova/lib/prepare.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 3bb8d16c1..d2cbcece5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -280,7 +280,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var modernWebViewOnly = platformConfig.getPreference('ModernWebViewOnly', 'ios') === 'true'; + var wkWebViewOnly = platformConfig.getPreference('WKWebViewOnly') === 'true'; var project; @@ -318,7 +318,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion); } - if (modernWebViewOnly) { + if (wkWebViewOnly) { events.emit('verbose', 'Set MODERN_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('MODERN_WEB_VIEW_ONLY', '1'); } From ee8234e7be52b005c99534b6a65c4c4b8ec3b4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 12:24:41 +0200 Subject: [PATCH 06/21] update project configuration of CordovaLib during prepare step --- .../Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h | 2 +- .../Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m | 2 +- .../Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h | 2 +- .../Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m | 2 +- .../CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h | 2 +- .../CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m | 2 +- CordovaLib/Classes/Public/CDVUserAgentUtil.m | 4 ++-- CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 7 +++++++ bin/templates/project/__TEMP__.xcodeproj/project.pbxproj | 2 ++ bin/templates/scripts/cordova/build-debug.xcconfig | 2 +- bin/templates/scripts/cordova/build.xcconfig | 2 +- bin/templates/scripts/cordova/lib/prepare.js | 7 ++++--- bin/templates/scripts/cordova/lib/projectFile.js | 6 ++++++ 13 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h index a1de6bfd8..0227f8f19 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h @@ -17,7 +17,7 @@ under the License. */ - #if !MODERN_WEB_VIEW_ONLY + #if !WK_WEB_VIEW_ONLY #import #import diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m index 98a3fbca2..3bdc645d6 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m @@ -76,7 +76,7 @@ Licensed to the Apache Software Foundation (ASF) under one // TODO: Record order when page is re-navigated before the first navigation finishes. // - #if !MODERN_WEB_VIEW_ONLY + #if !WK_WEB_VIEW_ONLY #import "CDVUIWebViewDelegate.h" diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h index 673ff95c6..9b4bf187a 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.h @@ -22,7 +22,7 @@ @interface CDVUIWebViewEngine : CDVPlugin -#if !MODERN_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY @property (nonatomic, strong, readonly) id uiWebViewDelegate; #endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m index e354e9a84..e5767b5be 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewEngine.m @@ -17,7 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ -#if !MODERN_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY #import "CDVUIWebViewEngine.h" #import "CDVUIWebViewDelegate.h" diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h index 886a347d1..c7907d8cd 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h @@ -17,7 +17,7 @@ under the License. */ - #if !MODERN_WEB_VIEW_ONLY + #if !WK_WEB_VIEW_ONLY #import #import "CDVUIWebViewEngine.h" diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m index 8be2899bb..fa2c4bca2 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m @@ -17,7 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ - #if !MODERN_WEB_VIEW_ONLY + #if !WK_WEB_VIEW_ONLY #import "CDVUIWebViewNavigationDelegate.h" #import diff --git a/CordovaLib/Classes/Public/CDVUserAgentUtil.m b/CordovaLib/Classes/Public/CDVUserAgentUtil.m index bca0d9de1..5ab660c37 100644 --- a/CordovaLib/Classes/Public/CDVUserAgentUtil.m +++ b/CordovaLib/Classes/Public/CDVUserAgentUtil.m @@ -32,7 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one static NSInteger gCurrentLockToken = 0; static NSMutableArray* gPendingSetUserAgentBlocks = nil; - #if MODERN_WEB_VIEW_ONLY + #if WK_WEB_VIEW_ONLY @interface WKWebView(SynchronousEvaluateJavaScript) - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script; @end @@ -86,7 +86,7 @@ + (NSString*)originalUserAgent BOOL cachedValueIsOld = ![systemAndLocale isEqualToString:cordovaUserAgentVersion]; if ((gOriginalUserAgent == nil) || cachedValueIsOld) { - #if MODERN_WEB_VIEW_ONLY + #if WK_WEB_VIEW_ONLY WKWebView* sampleWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; #else UIWebView* sampleWebView = [[UIWebView alloc] initWithFrame:CGRectZero]; diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj index 682c4c55a..cb6716388 100644 --- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj +++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj @@ -643,6 +643,7 @@ GCC_PREFIX_HEADER = CordovaLib_Prefix.pch; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", + "WK_WEB_VIEW_ONLY=$(WK_WEB_VIEW_ONLY)", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -659,6 +660,7 @@ PRODUCT_NAME = Cordova; SDKROOT = iphoneos; SKIP_INSTALL = YES; + WK_WEB_VIEW_ONLY = 0; }; name = Debug; }; @@ -703,6 +705,10 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = CordovaLib_Prefix.pch; + GCC_PREPROCESSOR_DEFINITIONS = ( + "WK_WEB_VIEW_ONLY=$(WK_WEB_VIEW_ONLY)", + "$(inherited)", + ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -717,6 +723,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; VALIDATE_PRODUCT = YES; + WK_WEB_VIEW_ONLY = 0; }; name = Release; }; diff --git a/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj b/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj index 0e6bc3bc3..58bee5dd4 100755 --- a/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj +++ b/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj @@ -389,6 +389,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SKIP_INSTALL = NO; + WK_WEB_VIEW_ONLY = 0; }; name = Debug; }; @@ -428,6 +429,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; SDKROOT = iphoneos; SKIP_INSTALL = NO; + WK_WEB_VIEW_ONLY = 0; }; name = Release; }; diff --git a/bin/templates/scripts/cordova/build-debug.xcconfig b/bin/templates/scripts/cordova/build-debug.xcconfig index 3f4767d22..eab2d7da9 100644 --- a/bin/templates/scripts/cordova/build-debug.xcconfig +++ b/bin/templates/scripts/cordova/build-debug.xcconfig @@ -23,7 +23,7 @@ #include "build.xcconfig" -GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 +GCC_PREPROCESSOR_DEFINITIONS = ($inherited) DEBUG=1 #include "build-extras.xcconfig" diff --git a/bin/templates/scripts/cordova/build.xcconfig b/bin/templates/scripts/cordova/build.xcconfig index ad6814439..3c8b9307d 100644 --- a/bin/templates/scripts/cordova/build.xcconfig +++ b/bin/templates/scripts/cordova/build.xcconfig @@ -42,4 +42,4 @@ SWIFT_OBJC_BRIDGING_HEADER = $(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h // (CB-11854) CODE_SIGN_ENTITLEMENTS = $(PROJECT_DIR)/$(PROJECT_NAME)/Entitlements-$(CONFIGURATION).plist -GCC_PREPROCESSOR_DEFINITIONS = MODERN_WEB_VIEW_ONLY=$(MODERN_WEB_VIEW_ONLY) +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) WK_WEB_VIEW_ONLY=$(WK_WEB_VIEW_ONLY) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index d2cbcece5..d2e2b207f 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -294,7 +294,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { // no build settings provided and we don't need to update build settings for launch storyboards, // then we don't need to parse and update .pbxproj file - if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion && !modernWebViewOnly) { + if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion && !wkWebViewOnly) { return Q(); } @@ -319,8 +319,9 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { } if (wkWebViewOnly) { - events.emit('verbose', 'Set MODERN_WEB_VIEW_ONLY.'); - project.xcode.updateBuildProperty('MODERN_WEB_VIEW_ONLY', '1'); + events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); + project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + project.xcode_lib.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); diff --git a/bin/templates/scripts/cordova/lib/projectFile.js b/bin/templates/scripts/cordova/lib/projectFile.js index 8a3f7e516..39ef7e9a8 100644 --- a/bin/templates/scripts/cordova/lib/projectFile.js +++ b/bin/templates/scripts/cordova/lib/projectFile.js @@ -49,6 +49,10 @@ function parseProjectFile (locations) { throw new CordovaError('Could not find *-Info.plist file, or config.xml file.'); } + var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); + var xcodeproj_lib = xcode.project(pbxPath_lib); + xcodeproj_lib.parseSync(); + var frameworks_file = path.join(project_dir, 'frameworks.json'); var frameworks = {}; try { @@ -63,6 +67,7 @@ function parseProjectFile (locations) { plugins_dir: pluginsDir, resources_dir: resourcesDir, xcode: xcodeproj, + xcode_lib: xcodeproj_lib, xcode_path: xcode_dir, pbx: pbxPath, projectDir: project_dir, @@ -70,6 +75,7 @@ function parseProjectFile (locations) { www: path.join(project_dir, 'www'), write: function () { fs.writeFileSync(pbxPath, xcodeproj.writeSync()); + fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); if (Object.keys(this.frameworks).length === 0) { // If there is no framework references remain in the project, just remove this file shell.rm('-rf', frameworks_file); From 9e65e591ada3263b41377776a1db3dd6faa39f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 13:45:57 +0200 Subject: [PATCH 07/21] make sure we have separate xcode projects --- bin/templates/scripts/cordova/lib/projectFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/projectFile.js b/bin/templates/scripts/cordova/lib/projectFile.js index 39ef7e9a8..d9ce9aabb 100644 --- a/bin/templates/scripts/cordova/lib/projectFile.js +++ b/bin/templates/scripts/cordova/lib/projectFile.js @@ -50,7 +50,7 @@ function parseProjectFile (locations) { } var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - var xcodeproj_lib = xcode.project(pbxPath_lib); + var xcodeproj_lib = new xcode.project(pbxPath_lib); xcodeproj_lib.parseSync(); var frameworks_file = path.join(project_dir, 'frameworks.json'); From a2d239d1aebc3e529c6360461d0331e2408e4d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 13:47:57 +0200 Subject: [PATCH 08/21] experimenting --- bin/templates/scripts/cordova/lib/prepare.js | 2 +- bin/templates/scripts/cordova/lib/projectFile.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index d2e2b207f..94c5bc427 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -321,7 +321,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - project.xcode_lib.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + //project.xcode_lib.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); diff --git a/bin/templates/scripts/cordova/lib/projectFile.js b/bin/templates/scripts/cordova/lib/projectFile.js index d9ce9aabb..aa484565f 100644 --- a/bin/templates/scripts/cordova/lib/projectFile.js +++ b/bin/templates/scripts/cordova/lib/projectFile.js @@ -49,9 +49,9 @@ function parseProjectFile (locations) { throw new CordovaError('Could not find *-Info.plist file, or config.xml file.'); } - var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - var xcodeproj_lib = new xcode.project(pbxPath_lib); - xcodeproj_lib.parseSync(); + //var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); + //var xcodeproj_lib = new xcode.project(pbxPath_lib); + //xcodeproj_lib.parseSync(); var frameworks_file = path.join(project_dir, 'frameworks.json'); var frameworks = {}; @@ -67,7 +67,7 @@ function parseProjectFile (locations) { plugins_dir: pluginsDir, resources_dir: resourcesDir, xcode: xcodeproj, - xcode_lib: xcodeproj_lib, + //xcode_lib: xcodeproj_lib, xcode_path: xcode_dir, pbx: pbxPath, projectDir: project_dir, @@ -75,7 +75,7 @@ function parseProjectFile (locations) { www: path.join(project_dir, 'www'), write: function () { fs.writeFileSync(pbxPath, xcodeproj.writeSync()); - fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); + //fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); if (Object.keys(this.frameworks).length === 0) { // If there is no framework references remain in the project, just remove this file shell.rm('-rf', frameworks_file); From ccfe8e1f7dbc3bd93633ce7a41a644af391d162b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 13:51:41 +0200 Subject: [PATCH 09/21] explicitly initializing new xcode project --- bin/templates/scripts/cordova/lib/projectFile.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/projectFile.js b/bin/templates/scripts/cordova/lib/projectFile.js index aa484565f..b560c06ab 100644 --- a/bin/templates/scripts/cordova/lib/projectFile.js +++ b/bin/templates/scripts/cordova/lib/projectFile.js @@ -37,7 +37,7 @@ function parseProjectFile (locations) { return cachedProjectFiles[project_dir]; } - var xcodeproj = xcode.project(pbxPath); + var xcodeproj = new xcode.project(pbxPath); xcodeproj.parseSync(); var xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection(); @@ -49,9 +49,9 @@ function parseProjectFile (locations) { throw new CordovaError('Could not find *-Info.plist file, or config.xml file.'); } - //var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - //var xcodeproj_lib = new xcode.project(pbxPath_lib); - //xcodeproj_lib.parseSync(); + var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); + var xcodeproj_lib = new xcode.project(pbxPath_lib); + xcodeproj_lib.parseSync(); var frameworks_file = path.join(project_dir, 'frameworks.json'); var frameworks = {}; @@ -67,7 +67,7 @@ function parseProjectFile (locations) { plugins_dir: pluginsDir, resources_dir: resourcesDir, xcode: xcodeproj, - //xcode_lib: xcodeproj_lib, + xcode_lib: xcodeproj_lib, xcode_path: xcode_dir, pbx: pbxPath, projectDir: project_dir, @@ -75,7 +75,7 @@ function parseProjectFile (locations) { www: path.join(project_dir, 'www'), write: function () { fs.writeFileSync(pbxPath, xcodeproj.writeSync()); - //fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); + fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); if (Object.keys(this.frameworks).length === 0) { // If there is no framework references remain in the project, just remove this file shell.rm('-rf', frameworks_file); From 2ab37e99af09c0ca5fa765f73c1d8f2fe0ec8791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 13:56:50 +0200 Subject: [PATCH 10/21] don't try loading two xcode project files --- bin/templates/scripts/cordova/lib/projectFile.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/projectFile.js b/bin/templates/scripts/cordova/lib/projectFile.js index b560c06ab..8a3f7e516 100644 --- a/bin/templates/scripts/cordova/lib/projectFile.js +++ b/bin/templates/scripts/cordova/lib/projectFile.js @@ -37,7 +37,7 @@ function parseProjectFile (locations) { return cachedProjectFiles[project_dir]; } - var xcodeproj = new xcode.project(pbxPath); + var xcodeproj = xcode.project(pbxPath); xcodeproj.parseSync(); var xcBuildConfiguration = xcodeproj.pbxXCBuildConfigurationSection(); @@ -49,10 +49,6 @@ function parseProjectFile (locations) { throw new CordovaError('Could not find *-Info.plist file, or config.xml file.'); } - var pbxPath_lib = path.join(project_dir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - var xcodeproj_lib = new xcode.project(pbxPath_lib); - xcodeproj_lib.parseSync(); - var frameworks_file = path.join(project_dir, 'frameworks.json'); var frameworks = {}; try { @@ -67,7 +63,6 @@ function parseProjectFile (locations) { plugins_dir: pluginsDir, resources_dir: resourcesDir, xcode: xcodeproj, - xcode_lib: xcodeproj_lib, xcode_path: xcode_dir, pbx: pbxPath, projectDir: project_dir, @@ -75,7 +70,6 @@ function parseProjectFile (locations) { www: path.join(project_dir, 'www'), write: function () { fs.writeFileSync(pbxPath, xcodeproj.writeSync()); - fs.writeFileSync(pbxPath_lib, xcodeproj_lib.writeSync()); if (Object.keys(this.frameworks).length === 0) { // If there is no framework references remain in the project, just remove this file shell.rm('-rf', frameworks_file); From 84cc662d238774b7544bce6adbc2570105fd02cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 14:04:06 +0200 Subject: [PATCH 11/21] try again loading subproject file --- bin/templates/scripts/cordova/lib/prepare.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 94c5bc427..08de4fc6f 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -24,6 +24,7 @@ var path = require('path'); var shell = require('shelljs'); var unorm = require('unorm'); var plist = require('plist'); +var xcode = require('xcode'); var URL = require('url'); var events = require('cordova-common').events; var xmlHelpers = require('cordova-common').xmlHelpers; @@ -321,7 +322,13 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - //project.xcode_lib.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + + // update CordovaLib Xcode project, too + var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); + var xcodeproj = xcode.project(pbxPath); + xcodeproj.parseSync(); + xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + fs.writeFileSync(pbxPath, xcodeproj.writeSync()); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); From 9d8c66300d93730bf09cb0cd22613b6095289635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 14:26:32 +0200 Subject: [PATCH 12/21] maybe this is a scoping issue --- bin/templates/scripts/cordova/lib/prepare.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 08de4fc6f..ff8f49e0d 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -322,7 +322,13 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + } + + updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); + + project.write(); + if (wkWebViewOnly) { // update CordovaLib Xcode project, too var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); var xcodeproj = xcode.project(pbxPath); @@ -331,10 +337,6 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { fs.writeFileSync(pbxPath, xcodeproj.writeSync()); } - updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); - - project.write(); - return Q(); } From 15dd2fa49713991f101129736d9fda918963a245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 14:29:47 +0200 Subject: [PATCH 13/21] check if project file exists --- bin/templates/scripts/cordova/lib/prepare.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index ff8f49e0d..c19e71afa 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -331,10 +331,14 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { // update CordovaLib Xcode project, too var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - var xcodeproj = xcode.project(pbxPath); - xcodeproj.parseSync(); - xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - fs.writeFileSync(pbxPath, xcodeproj.writeSync()); + if (fs.existsSync(pbxPath)) { + var xcodeproj = xcode.project(pbxPath); + xcodeproj.parseSync(); + xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + fs.writeFileSync(pbxPath, xcodeproj.writeSync()); + } else { + events.emit('error', 'Project file does not exist at ' + pbxPath); + } } return Q(); From d7c74cc4d95aea7207a0cca58fe28e858e796ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 15:08:07 +0200 Subject: [PATCH 14/21] try with synchronous installation of CordovaLib --- bin/lib/create.js | 49 +++++++++----------- bin/templates/scripts/cordova/lib/prepare.js | 20 +++----- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/bin/lib/create.js b/bin/lib/create.js index ddf6cbfe5..d95a39b89 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -37,33 +37,30 @@ function copyJsAndCordovaLib (projectPath, projectName, use_shared) { shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), path.join(projectPath, 'platform_www')); shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'platform_www')); - fs.lstat(path.join(projectPath, 'CordovaLib'), function (err, stats) { - if (!err) { - if (stats.isSymbolicLink()) { - fs.unlinkSync(path.join(projectPath, 'CordovaLib')); - } else { - shell.rm('-rf', path.join(projectPath, 'CordovaLib')); - } - } + var stats = fs.lstatSync(path.join(projectPath, 'CordovaLib')); + if (stats.isSymbolicLink()) { + fs.unlinkSync(path.join(projectPath, 'CordovaLib')); + } else { + shell.rm('-rf', path.join(projectPath, 'CordovaLib')); + } - if (use_shared) { - update_cordova_subproject([path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj')]); - // Symlink not used in project file, but is currently required for plugman because - // it reads the VERSION file from it (instead of using the cordova/version script - // like it should). - fs.symlinkSync(path.join(ROOT, 'CordovaLib'), path.join(projectPath, 'CordovaLib')); - } else { - var r = path.join(projectPath, projectName); - shell.mkdir('-p', path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); - shell.cp('-f', path.join(r, '.gitignore'), projectPath); - shell.cp('-rf', path.join(ROOT, 'CordovaLib', 'Classes'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'VERSION'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib_Prefix.pch'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); - update_cordova_subproject([path.join(r + '.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj')]); - } - }); + if (use_shared) { + update_cordova_subproject([path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj')]); + // Symlink not used in project file, but is currently required for plugman because + // it reads the VERSION file from it (instead of using the cordova/version script + // like it should). + fs.symlinkSync(path.join(ROOT, 'CordovaLib'), path.join(projectPath, 'CordovaLib')); + } else { + var r = path.join(projectPath, projectName); + shell.mkdir('-p', path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); + shell.cp('-f', path.join(r, '.gitignore'), projectPath); + shell.cp('-rf', path.join(ROOT, 'CordovaLib', 'Classes'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'VERSION'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib_Prefix.pch'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); + update_cordova_subproject([path.join(r + '.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj')]); + } } function copyScripts (projectPath, projectName) { diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index c19e71afa..08de4fc6f 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -322,25 +322,19 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + + // update CordovaLib Xcode project, too + var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); + var xcodeproj = xcode.project(pbxPath); + xcodeproj.parseSync(); + xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + fs.writeFileSync(pbxPath, xcodeproj.writeSync()); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); project.write(); - if (wkWebViewOnly) { - // update CordovaLib Xcode project, too - var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - if (fs.existsSync(pbxPath)) { - var xcodeproj = xcode.project(pbxPath); - xcodeproj.parseSync(); - xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - fs.writeFileSync(pbxPath, xcodeproj.writeSync()); - } else { - events.emit('error', 'Project file does not exist at ' + pbxPath); - } - } - return Q(); } From 431a7d3d62a21571dcc0c20e9fef8775c300603d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 15:27:32 +0200 Subject: [PATCH 15/21] update CordovaLib project file during create phase --- bin/lib/create.js | 72 ++++++++++++-------- bin/templates/scripts/cordova/Api.js | 4 +- bin/templates/scripts/cordova/lib/prepare.js | 8 --- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/bin/lib/create.js b/bin/lib/create.js index d95a39b89..b4501d28c 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -23,6 +23,7 @@ var shell = require('shelljs'); var Q = require('q'); var path = require('path'); var fs = require('fs'); +var xcode = require('xcode'); var xmlescape = require('xml-escape'); var ROOT = path.join(__dirname, '..', '..'); var events = require('cordova-common').events; @@ -32,35 +33,38 @@ function updateSubprojectHelp () { console.log('Usage: CordovaVersion/bin/update_cordova_project path/to/your/app.xcodeproj [path/to/CordovaLib.xcodeproj]'); } -function copyJsAndCordovaLib (projectPath, projectName, use_shared) { +function copyJsAndCordovaLib (projectPath, projectName, use_shared, config) { shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'www')); shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), path.join(projectPath, 'platform_www')); shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'platform_www')); - var stats = fs.lstatSync(path.join(projectPath, 'CordovaLib')); - if (stats.isSymbolicLink()) { - fs.unlinkSync(path.join(projectPath, 'CordovaLib')); - } else { - shell.rm('-rf', path.join(projectPath, 'CordovaLib')); - } + fs.lstat(path.join(projectPath, 'CordovaLib'), function (err, stats) { + if (!err) { + if (stats.isSymbolicLink()) { + fs.unlinkSync(path.join(projectPath, 'CordovaLib')); + } else { + shell.rm('-rf', path.join(projectPath, 'CordovaLib')); + } + } - if (use_shared) { - update_cordova_subproject([path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj')]); - // Symlink not used in project file, but is currently required for plugman because - // it reads the VERSION file from it (instead of using the cordova/version script - // like it should). - fs.symlinkSync(path.join(ROOT, 'CordovaLib'), path.join(projectPath, 'CordovaLib')); - } else { - var r = path.join(projectPath, projectName); - shell.mkdir('-p', path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); - shell.cp('-f', path.join(r, '.gitignore'), projectPath); - shell.cp('-rf', path.join(ROOT, 'CordovaLib', 'Classes'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'VERSION'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib_Prefix.pch'), path.join(projectPath, 'CordovaLib')); - shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); - update_cordova_subproject([path.join(r + '.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj')]); - } + if (use_shared) { + update_cordova_subproject([path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj'), config]); + // Symlink not used in project file, but is currently required for plugman because + // it reads the VERSION file from it (instead of using the cordova/version script + // like it should). + fs.symlinkSync(path.join(ROOT, 'CordovaLib'), path.join(projectPath, 'CordovaLib')); + } else { + var r = path.join(projectPath, projectName); + shell.mkdir('-p', path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); + shell.cp('-f', path.join(r, '.gitignore'), projectPath); + shell.cp('-rf', path.join(ROOT, 'CordovaLib', 'Classes'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'VERSION'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'cordova.js'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib_Prefix.pch'), path.join(projectPath, 'CordovaLib')); + shell.cp('-f', path.join(ROOT, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj')); + update_cordova_subproject([path.join(r + '.xcodeproj', 'project.pbxproj'), path.join(projectPath, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'), config]); + } + }); } function copyScripts (projectPath, projectName) { @@ -194,7 +198,7 @@ function relpath (_path, start) { * - : Path to a project template (override) * */ -exports.createProject = function (project_path, package_name, project_name, opts) { +exports.createProject = function (project_path, package_name, project_name, opts, config) { package_name = package_name || 'my.cordova.project'; project_name = project_name || 'CordovaExample'; var use_shared = !!opts.link; @@ -230,7 +234,7 @@ exports.createProject = function (project_path, package_name, project_name, opts shell.cp('-rf', path.join(project_template_dir, '*.xcconfig'), project_path); // CordovaLib stuff - copyJsAndCordovaLib(project_path, project_name, use_shared); + copyJsAndCordovaLib(project_path, project_name, use_shared, config); copyScripts(project_path, project_name); events.emit('log', generateDoneMessage('create', use_shared)); @@ -261,17 +265,20 @@ function generateDoneMessage (type, link) { } function update_cordova_subproject (argv) { - if (argv.length < 1 || argv.length > 2) { + if (argv.length < 1 || argv.length > 3) { updateSubprojectHelp(); throw new Error('Usage error for update_cordova_subproject'); } var projectPath = AbsProjectPath(argv[0]); var cordovaLibXcodePath; - if (argv.length < 2) { + var projectConfig; + if (argv.length < 3) { cordovaLibXcodePath = path.join(ROOT, 'CordovaLib', 'CordovaLib.xcodeproj'); + projectConfig = argv[1]; } else { cordovaLibXcodePath = AbsProjectPath(argv[1]); + projectConfig = argv[2]; } var parentProjectPath = AbsParentPath(projectPath); @@ -298,6 +305,15 @@ function update_cordova_subproject (argv) { if (!found) { throw new Error('Entry not found in project file for sub-project: ' + subprojectPath); } + + var wkWebViewOnly = projectConfig.getPreference('WKWebViewOnly') === 'true'; + if (wkWebViewOnly) { + var pbxPath = path.join(projectPath, 'project.pbxproj'); + var xcodeproj = xcode.project(pbxPath); + xcodeproj.parseSync(); + xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + fs.writeFileSync(pbxPath, xcodeproj.writeSync()); + } } exports.updateSubprojectHelp = updateSubprojectHelp; diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 73c1dbcdf..4f85f3241 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -103,7 +103,7 @@ function Api (platform, platformRootDir, events) { * Creates platform in a specified directory. * * @param {String} destination Destination directory, where install platform to - * @param {ConfigParser} [config] ConfgiParser instance, used to retrieve + * @param {ConfigParser} [config] ConfigParser instance, used to retrieve * project creation options, such as package id and project name. * @param {Object} [options] An options object. The most common options are: * @param {String} [options.customTemplate] A path to custom template, that @@ -127,7 +127,7 @@ Api.createPlatform = function (destination, config, options, events) { var result; try { result = require('../../../lib/create') - .createProject(destination, config.getAttribute('ios-CFBundleIdentifier') || config.packageName(), name, options) + .createProject(destination, config.getAttribute('ios-CFBundleIdentifier') || config.packageName(), name, options, config) .then(function () { // after platform is created we return Api instance based on new Api.js location // This is required to correctly resolve paths in the future api calls diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 08de4fc6f..e64a1491d 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -24,7 +24,6 @@ var path = require('path'); var shell = require('shelljs'); var unorm = require('unorm'); var plist = require('plist'); -var xcode = require('xcode'); var URL = require('url'); var events = require('cordova-common').events; var xmlHelpers = require('cordova-common').xmlHelpers; @@ -322,13 +321,6 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (wkWebViewOnly) { events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - - // update CordovaLib Xcode project, too - var pbxPath = path.join(project.projectDir, 'CordovaLib', 'CordovaLib.xcodeproj', 'project.pbxproj'); - var xcodeproj = xcode.project(pbxPath); - xcodeproj.parseSync(); - xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); - fs.writeFileSync(pbxPath, xcodeproj.writeSync()); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); From 419ab5b50bfefd08db51b63daad3381641284a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 15:34:32 +0200 Subject: [PATCH 16/21] fix path --- bin/lib/create.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/lib/create.js b/bin/lib/create.js index b4501d28c..07ea066e1 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -308,7 +308,7 @@ function update_cordova_subproject (argv) { var wkWebViewOnly = projectConfig.getPreference('WKWebViewOnly') === 'true'; if (wkWebViewOnly) { - var pbxPath = path.join(projectPath, 'project.pbxproj'); + var pbxPath = path.join(cordovaLibXcodePath, 'project.pbxproj'); var xcodeproj = xcode.project(pbxPath); xcodeproj.parseSync(); xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); From bfd834a34ac5a3201a8512b840d40f827ece298e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 15:47:01 +0200 Subject: [PATCH 17/21] minor adjustments --- .../Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h | 2 +- .../Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m | 2 +- .../CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h | 2 +- .../CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m | 2 +- CordovaLib/Classes/Public/CDVUserAgentUtil.m | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h index 0227f8f19..8118d5f04 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.h @@ -17,7 +17,7 @@ under the License. */ - #if !WK_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY #import #import diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m index 3bdc645d6..ddef8be13 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewDelegate.m @@ -76,7 +76,7 @@ Licensed to the Apache Software Foundation (ASF) under one // TODO: Record order when page is re-navigated before the first navigation finishes. // - #if !WK_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY #import "CDVUIWebViewDelegate.h" diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h index c7907d8cd..9b9b31f1f 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.h @@ -17,7 +17,7 @@ under the License. */ - #if !WK_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY #import #import "CDVUIWebViewEngine.h" diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m index fa2c4bca2..a918e2d7b 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m @@ -17,7 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ - #if !WK_WEB_VIEW_ONLY +#if !WK_WEB_VIEW_ONLY #import "CDVUIWebViewNavigationDelegate.h" #import diff --git a/CordovaLib/Classes/Public/CDVUserAgentUtil.m b/CordovaLib/Classes/Public/CDVUserAgentUtil.m index 5ab660c37..c5e9e2bcd 100644 --- a/CordovaLib/Classes/Public/CDVUserAgentUtil.m +++ b/CordovaLib/Classes/Public/CDVUserAgentUtil.m @@ -32,7 +32,9 @@ Licensed to the Apache Software Foundation (ASF) under one static NSInteger gCurrentLockToken = 0; static NSMutableArray* gPendingSetUserAgentBlocks = nil; - #if WK_WEB_VIEW_ONLY +#if WK_WEB_VIEW_ONLY +#import + @interface WKWebView(SynchronousEvaluateJavaScript) - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script; @end From 63ffa5541748d0cc9fd5c48c30ba543a3d6b8ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 15:55:24 +0200 Subject: [PATCH 18/21] ouch --- bin/templates/scripts/cordova/build-debug.xcconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/build-debug.xcconfig b/bin/templates/scripts/cordova/build-debug.xcconfig index eab2d7da9..7e7985bb5 100644 --- a/bin/templates/scripts/cordova/build-debug.xcconfig +++ b/bin/templates/scripts/cordova/build-debug.xcconfig @@ -23,7 +23,7 @@ #include "build.xcconfig" -GCC_PREPROCESSOR_DEFINITIONS = ($inherited) DEBUG=1 +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG=1 #include "build-extras.xcconfig" From 0cd7072b6e49889067041582f443e0d10199b5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 17:13:59 +0200 Subject: [PATCH 19/21] exclude some more code to get rid of UIWebView traces --- .../CDVIntentAndNavigationFilter.h | 4 ++++ .../CDVIntentAndNavigationFilter.m | 16 ++++++++++------ .../Plugins/CDVLocalStorage/CDVLocalStorage.m | 6 ++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h index 94c10de8c..93a373292 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h +++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h @@ -17,6 +17,8 @@ under the License. */ +#if !WK_WEB_VIEW_ONLY + #import #import @@ -32,3 +34,5 @@ typedef NS_ENUM(NSInteger, CDVIntentAndNavigationFilterValue) { + (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue; + (BOOL)shouldOpenURLRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType; @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m index ccfe77e9b..d02bb0d4f 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m +++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m @@ -17,6 +17,8 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ +#if !WK_WEB_VIEW_ONLY + #import "CDVIntentAndNavigationFilter.h" #import @@ -75,10 +77,10 @@ + (CDVIntentAndNavigationFilterValue) filterUrl:(NSURL*)url intentsWhitelist:(CD { // a URL can only allow-intent OR allow-navigation, if both are specified, // only allow-navigation is allowed - + BOOL allowNavigationsPass = [navigationsWhitelist URLIsAllowed:url logFailure:NO]; BOOL allowIntentPass = [intentsWhitelist URLIsAllowed:url logFailure:NO]; - + if (allowNavigationsPass && allowIntentPass) { return CDVIntentAndNavigationFilterValueNavigationAllowed; } else if (allowNavigationsPass) { @@ -86,7 +88,7 @@ + (CDVIntentAndNavigationFilterValue) filterUrl:(NSURL*)url intentsWhitelist:(CD } else if (allowIntentPass) { return CDVIntentAndNavigationFilterValueIntentAllowed; } - + return CDVIntentAndNavigationFilterValueNoneAllowed; } @@ -108,9 +110,9 @@ + (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIW { NSString* allowIntents_whitelistRejectionFormatString = @"ERROR External navigation rejected - not set for url='%@'"; NSString* allowNavigations_whitelistRejectionFormatString = @"ERROR Internal navigation rejected - not set for url='%@'"; - + NSURL* url = [request URL]; - + switch (filterValue) { case CDVIntentAndNavigationFilterValueNavigationAllowed: return YES; @@ -120,7 +122,7 @@ + (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIW if ([[self class] shouldOpenURLRequest:request navigationType:navigationType]){ [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } - + // consume the request (i.e. no error) if it wasn't handled above return NO; case CDVIntentAndNavigationFilterValueNoneAllowed: @@ -140,3 +142,5 @@ - (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIW } @end + +#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVLocalStorage/CDVLocalStorage.m b/CordovaLib/Classes/Private/Plugins/CDVLocalStorage/CDVLocalStorage.m index 21b5cd9f4..25c48536d 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVLocalStorage/CDVLocalStorage.m +++ b/CordovaLib/Classes/Private/Plugins/CDVLocalStorage/CDVLocalStorage.m @@ -23,13 +23,19 @@ Licensed to the Apache Software Foundation (ASF) under one @interface CDVLocalStorage () @property (nonatomic, readwrite, strong) NSMutableArray* backupInfo; // array of CDVBackupInfo objects +#if !WK_WEB_VIEW_ONLY @property (nonatomic, readwrite, weak) id webviewDelegate; +#endif @end @implementation CDVLocalStorage +#if WK_WEB_VIEW_ONLY +@synthesize backupInfo; +#else @synthesize backupInfo, webviewDelegate; +#endif - (void)pluginInitialize { From c19b6fa8ecf3eecc730f1682ff028b4f809ced5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Fri, 30 Aug 2019 17:24:06 +0200 Subject: [PATCH 20/21] re-enable plugin for WKWebView --- .../CDVIntentAndNavigationFilter.h | 14 ++++++----- .../CDVIntentAndNavigationFilter.m | 24 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h index 93a373292..a038dbdee 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h +++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.h @@ -17,11 +17,15 @@ under the License. */ -#if !WK_WEB_VIEW_ONLY - #import #import +#if WK_WEB_VIEW_ONLY +#define CDVWebViewNavigationType int +#else +#define CDVWebViewNavigationType UIWebViewNavigationType +#endif + typedef NS_ENUM(NSInteger, CDVIntentAndNavigationFilterValue) { CDVIntentAndNavigationFilterValueIntentAllowed, CDVIntentAndNavigationFilterValueNavigationAllowed, @@ -31,8 +35,6 @@ typedef NS_ENUM(NSInteger, CDVIntentAndNavigationFilterValue) { @interface CDVIntentAndNavigationFilter : CDVPlugin + (CDVIntentAndNavigationFilterValue) filterUrl:(NSURL*)url intentsWhitelist:(CDVWhitelist*)intentsWhitelist navigationsWhitelist:(CDVWhitelist*)navigationsWhitelist; -+ (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue; -+ (BOOL)shouldOpenURLRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType; ++ (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(CDVWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue; ++ (BOOL)shouldOpenURLRequest:(NSURLRequest*)request navigationType:(CDVWebViewNavigationType)navigationType; @end - -#endif diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m index d02bb0d4f..b656cd9eb 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m +++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m @@ -17,8 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ -#if !WK_WEB_VIEW_ONLY - #import "CDVIntentAndNavigationFilter.h" #import @@ -97,16 +95,24 @@ - (CDVIntentAndNavigationFilterValue) filterUrl:(NSURL*)url return [[self class] filterUrl:url intentsWhitelist:self.allowIntentsWhitelist navigationsWhitelist:self.allowNavigationsWhitelist]; } -+ (BOOL)shouldOpenURLRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType +#if WK_WEB_VIEW_ONLY +#define CDVWebViewNavigationTypeLinkClicked 0 +#define CDVWebViewNavigationTypeOther 5 +#else +#define CDVWebViewNavigationTypeLinkClicked UIWebViewNavigationTypeLinkClicked +#define CDVWebViewNavigationTypeOther UIWebViewNavigationTypeOther +#endif + ++ (BOOL)shouldOpenURLRequest:(NSURLRequest*)request navigationType:(CDVWebViewNavigationType)navigationType { - return (UIWebViewNavigationTypeLinkClicked == navigationType || - (UIWebViewNavigationTypeOther == navigationType && + return (CDVWebViewNavigationTypeLinkClicked == navigationType || + (CDVWebViewNavigationTypeOther == navigationType && [[request.mainDocumentURL absoluteString] isEqualToString:[request.URL absoluteString]] ) ); } -+ (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue ++ (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(CDVWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue { NSString* allowIntents_whitelistRejectionFormatString = @"ERROR External navigation rejected - not set for url='%@'"; NSString* allowNavigations_whitelistRejectionFormatString = @"ERROR Internal navigation rejected - not set for url='%@'"; @@ -129,18 +135,16 @@ + (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIW // allow-navigation attempt failed for sure NSLog(@"%@", [NSString stringWithFormat:allowNavigations_whitelistRejectionFormatString, [url absoluteString]]); // anchor tag link means it was an allow-intent attempt that failed as well - if (UIWebViewNavigationTypeLinkClicked == navigationType) { + if (CDVWebViewNavigationTypeLinkClicked == navigationType) { NSLog(@"%@", [NSString stringWithFormat:allowIntents_whitelistRejectionFormatString, [url absoluteString]]); } return NO; } } -- (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType +- (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(CDVWebViewNavigationType)navigationType { return [[self class] shouldOverrideLoadWithRequest:request navigationType:navigationType filterValue:[self filterUrl:request.URL]]; } @end - -#endif From f7a894892bf49b3220c7bc6144e595f6abcee15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Sat, 9 Nov 2019 12:31:39 +0100 Subject: [PATCH 21/21] make prepare also update CordovaLib project --- bin/templates/scripts/cordova/lib/prepare.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index e64a1491d..708e214cc 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -34,6 +34,7 @@ var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger; var PluginInfoProvider = require('cordova-common').PluginInfoProvider; var FileUpdater = require('cordova-common').FileUpdater; var projectFile = require('./projectFile'); +var xcode = require('xcode'); // launch storyboard and related constants var LAUNCHIMAGE_BUILD_SETTING = 'ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME'; @@ -280,7 +281,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var wkWebViewOnly = platformConfig.getPreference('WKWebViewOnly') === 'true'; + var wkWebViewOnly = platformConfig.getPreference('WKWebViewOnly'); var project; @@ -317,10 +318,21 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".'); project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion); } - if (wkWebViewOnly) { - events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); - project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', '1'); + var wkwebviewValue = '1'; + if (wkWebViewOnly === 'true') { + events.emit('verbose', 'Set WK_WEB_VIEW_ONLY.'); + } else { + wkwebviewValue = '0'; + events.emit('verbose', 'Unset WK_WEB_VIEW_ONLY.'); + } + project.xcode.updateBuildProperty('WK_WEB_VIEW_ONLY', wkwebviewValue); + var cordovaLibXcodePath = path.join(locations.root, 'CordovaLib', 'CordovaLib.xcodeproj'); + var pbxPath = path.join(cordovaLibXcodePath, 'project.pbxproj'); + var xcodeproj = xcode.project(pbxPath); + xcodeproj.parseSync(); + xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', wkwebviewValue); + fs.writeFileSync(pbxPath, xcodeproj.writeSync()); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist);