Fix cordova-ios v6 issues and remove UIWebView support (#658)

* Fix issues with cordova ios 6

Fix blank screen appearing after CodePush update
Remove support for UIWebview
This commit is contained in:
Ruslan Bikkinin 2020-10-19 12:55:19 +03:00 коммит произвёл GitHub
Родитель 95cc846a72
Коммит 5b9f027ec7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 52 добавлений и 28 удалений

Просмотреть файл

@ -35,7 +35,11 @@ In order to ensure that your end users always have a functioning version of your
Cordova 5.0.0+ is fully supported, along with the following associated platforms:
* Android ([cordova-android](https://github.com/apache/cordova-android) 4.0.0+) - *Including CrossWalk!* *Note: Only on TLS 1.2 compatible devices*
* iOS ([cordova-ios](https://github.com/apache/cordova-ios) 3.9.0+) - *Note: In order to use CodePush along with the [`cordova-plugin-wkwebview-engine`](https://github.com/apache/cordova-plugin-wkwebview-engine) plugin, you need to install `v1.5.1-beta+` version of `cordova-plugin-code-push`, which includes full support for apps using either WebView.*
* iOS ([cordova-ios](https://github.com/apache/cordova-ios) 3.9.0+) - please see notes below.
> Note: Starting with v2.0.0 `cordova-plugin-code-push` doesn't support apps using UIWebView due to [Apple officially deprecated it and discourage developers from using it](https://developer.apple.com/news/?id=12232019b). Prior versions of the plugin still support UIWebView but be aware that the App Store will no longer accept new apps using UIWebView as of April 2020 and app updates using UIWebView as of December 2020.
> Note: In order to use CodePush along with the [`cordova-plugin-wkwebview-engine`](https://github.com/apache/cordova-plugin-wkwebview-engine) plugin, you need to install `v1.5.1-beta+` version of `cordova-plugin-code-push`, which includes full support for apps using either WebView. Please see [Using WKWebView](#using-wkwebview) section for more information of how to confiure your app to use `cordova-plugin-wkwebview-engine`.
To check which versions of each Cordova platform you are currently using, you can run the following command and inspect the `Installed platforms` list:
@ -123,10 +127,15 @@ With the CodePush plugin installed, configure your app to use it via the followi
You are now ready to use the plugin in the application code. See the [sample applications](/samples) for examples and the API documentation for more details.
*NOTE: There is a possibility to specify WebView engine on the plugin build phase. By default UIWebView engine is used. You can force plugin to use WKWebView by adding this iOS specific preference:*
```xml
<preference name="WKWebViewOnly" value="true" />
```
### Using WKWebView
For cordova-ios v4-v5 there is a possibility to specify WebView engine on the plugin build phase. By default UIWebView engine is used. To use WKWebView engine please do the following:
* Install [cordova-plugin-wkwebview-engine](https://github.com/apache/cordova-plugin-wkwebview-engine#installation)
* [Configure your app](https://github.com/apache/cordova-plugin-wkwebview-engine#required-permissions) to use WKWebView
> Note: `cordova-plugin-wkwebview-engine` is just a workaround for cordova-ios v4-v5 users to be able to use WKWebView in their apps to avoid stop accepting updates via AppStore as of December 2020.
Cordova-ios v6+ has full support for native WKWebView and doesn't require `cordova-plugin-wkwebview-engine`.
## Plugin Usage

Просмотреть файл

@ -1,6 +1,7 @@
#import <Cordova/CDV.h>
#import <Cordova/CDVConfigParser.h>
#import <Cordova/CDVWebViewEngineProtocol.h>
#import <Cordova/NSDictionary+CordovaPreferences.h>
#import "CodePush.h"
#import "CodePushPackageMetadata.h"
#import "CodePushPackageManager.h"
@ -402,15 +403,17 @@ StatusReport* rollbackStatusReport = nil;
}
- (void)loadURL:(NSURL*)url {
// In order to make use of the "modern" Cordova platform, while still
// maintaining back-compat with Cordova iOS 3.9.0, we need to conditionally
// use the WebViewEngine for performing navigations only if the host app
// is running 4.0.0+, and fallback to directly using the WebView otherwise.
#if (WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0)) || defined(__CORDOVA_4_0_0)
[self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]];
#if WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0)
BOOL useUiWebView = NO;
#else
[(UIWebView*)self.webView loadRequest:[NSURLRequest requestWithURL:url]];
BOOL useUiWebView = YES;
#endif
if([Utilities CDVWebViewEngineAvailable] || !useUiWebView)
{
[self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]];
} else {
CPLog(@"Current version of CodePush plugin doesn't support UIWebView anymore. Please consider using version of the plugin below v2.0.0 or migrating to WkWebView. For more info please see https://developer.apple.com/news/?id=12232019b.");
}
}
+ (Boolean) hasIonicWebViewEngine:(id<CDVWebViewEngineProtocol>) webViewEngine {
@ -475,6 +478,11 @@ StatusReport* rollbackStatusReport = nil;
NSArray* realLocationArray = @[libraryLocation, @"NoCloud", packageLocation, @"www", startPage];
NSString* realStartPageLocation = [NSString pathWithComponents:realLocationArray];
if ([[NSFileManager defaultManager] fileExistsAtPath:realStartPageLocation]) {
// Fixes WKWebView unable to load start page from CodePush update directory
NSString* scheme = [self getAppScheme];
if ([Utilities CDVWebViewEngineAvailable] && ([realStartPageLocation hasPrefix:@"/_app_file_"] == NO) && !([scheme isEqualToString: @"file"] || scheme == nil)) {
realStartPageLocation = [@"/_app_file_" stringByAppendingString:realStartPageLocation];
}
return [NSURL fileURLWithPath:realStartPageLocation];
}
}
@ -546,5 +554,17 @@ StatusReport* rollbackStatusReport = nil;
}];
}
- (NSString*)getAppScheme {
NSDictionary* settings = self.commandDelegate.settings;
// Cordova
NSString *scheme = [settings cordovaSettingForKey:@"scheme"];
if (scheme != nil) {
return scheme;
}
// Ionic
scheme = [settings cordovaSettingForKey:@"iosScheme"];
return scheme;
}
@end

Просмотреть файл

@ -34,7 +34,6 @@ NSString* const LastVersionPreferenceLabelOrAppVersionKey = @"LAST_VERSION_LABEL
/* JS function to call: window.codePush.reportStatus(status: number, label: String, appVersion: String, deploymentKey: String) */
NSString* script = [NSString stringWithFormat:@"document.addEventListener(\"deviceready\", function () { window.codePush.reportStatus(%i, %@, %@, %@, %@, %@); });", (int)statusReport.status, labelParameter, appVersionParameter, deploymentKeyParameter, lastVersionLabelOrAppVersionParameter, lastVersionDeploymentKeyParameter];
#if WK_WEB_VIEW_ONLY
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
// The WKWebView requires JS evaluation to occur on the main
// thread starting with iOS11, so ensure that we dispatch to it before executing.
@ -42,21 +41,6 @@ NSString* const LastVersionPreferenceLabelOrAppVersionKey = @"LAST_VERSION_LABEL
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
});
}
#else
if ([webView respondsToSelector:@selector(evaluateJavaScript:completionHandler:)]) {
// The WKWebView requires JS evaluation to occur on the main
// thread starting with iOS11, so ensure that we dispatch to it before executing.
dispatch_async(dispatch_get_main_queue(), ^{
[webView performSelector:@selector(evaluateJavaScript:completionHandler:) withObject:script withObject: NULL];
});
} else if ([webView isKindOfClass:[UIWebView class]]) {
// The UIWebView requires JS evaluation to occur on the main
// thread, so ensure that we dispatch to it before executing.
dispatch_async(dispatch_get_main_queue(), ^{
[(UIWebView*)webView stringByEvaluatingJavaScriptFromString:script];
});
}
#endif
}
}

Просмотреть файл

@ -3,5 +3,6 @@
+ (NSString*)getApplicationVersion;
+ (NSString*)getApplicationTimestamp;
+ (NSDate*)getApplicationBuildTime;
+ (BOOL)CDVWebViewEngineAvailable;
@end

Просмотреть файл

@ -2,6 +2,8 @@
@implementation Utilities
static NSNumber* CDVWebViewEngineExists = nil;
+ (NSString*)getApplicationVersion{
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}
@ -24,6 +26,14 @@
return fileDate;
}
+ (BOOL)CDVWebViewEngineAvailable{
if(CDVWebViewEngineExists == nil) {
BOOL value = NSClassFromString(@"CDVWebViewEngine") != nil;
CDVWebViewEngineExists = [NSNumber numberWithBool:value];
}
return [CDVWebViewEngineExists boolValue];
}
void CPLog(NSString *formatString, ...) {
va_list args;
va_start(args, formatString);