|
1 | 1 | #import <Cordova/CDV.h>
|
2 | 2 | #import <Cordova/CDVConfigParser.h>
|
3 | 3 | #import <Cordova/CDVWebViewEngineProtocol.h>
|
| 4 | +#import <Cordova/NSDictionary+CordovaPreferences.h> |
4 | 5 | #import "CodePush.h"
|
5 | 6 | #import "CodePushPackageMetadata.h"
|
6 | 7 | #import "CodePushPackageManager.h"
|
@@ -402,15 +403,17 @@ - (BOOL)loadPackage:(NSString*)packageLocation {
|
402 | 403 | }
|
403 | 404 |
|
404 | 405 | - (void)loadURL:(NSURL*)url {
|
405 |
| - // In order to make use of the "modern" Cordova platform, while still |
406 |
| - // maintaining back-compat with Cordova iOS 3.9.0, we need to conditionally |
407 |
| - // use the WebViewEngine for performing navigations only if the host app |
408 |
| - // is running 4.0.0+, and fallback to directly using the WebView otherwise. |
409 |
| -#if (WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0)) || defined(__CORDOVA_4_0_0) |
410 |
| - [self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]]; |
| 406 | +#if WK_WEB_VIEW_ONLY && defined(__CORDOVA_4_0_0) |
| 407 | + BOOL useUiWebView = NO; |
411 | 408 | #else
|
412 |
| - [(UIWebView*)self.webView loadRequest:[NSURLRequest requestWithURL:url]]; |
| 409 | + BOOL useUiWebView = YES; |
413 | 410 | #endif
|
| 411 | + if([Utilities CDVWebViewEngineAvailable] || !useUiWebView) |
| 412 | + { |
| 413 | + [self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]]; |
| 414 | + } else { |
| 415 | + 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."); |
| 416 | + } |
414 | 417 | }
|
415 | 418 |
|
416 | 419 | + (Boolean) hasIonicWebViewEngine:(id<CDVWebViewEngineProtocol>) webViewEngine {
|
@@ -475,6 +478,11 @@ - (NSURL *)getStartPageURLForLocalPackage:(NSString*)packageLocation {
|
475 | 478 | NSArray* realLocationArray = @[libraryLocation, @"NoCloud", packageLocation, @"www", startPage];
|
476 | 479 | NSString* realStartPageLocation = [NSString pathWithComponents:realLocationArray];
|
477 | 480 | if ([[NSFileManager defaultManager] fileExistsAtPath:realStartPageLocation]) {
|
| 481 | + // Fixes WKWebView unable to load start page from CodePush update directory |
| 482 | + NSString* scheme = [self getAppScheme]; |
| 483 | + if ([Utilities CDVWebViewEngineAvailable] && ([realStartPageLocation hasPrefix:@"/_app_file_"] == NO) && !([scheme isEqualToString: @"file"] || scheme == nil)) { |
| 484 | + realStartPageLocation = [@"/_app_file_" stringByAppendingString:realStartPageLocation]; |
| 485 | + } |
478 | 486 | return [NSURL fileURLWithPath:realStartPageLocation];
|
479 | 487 | }
|
480 | 488 | }
|
@@ -546,5 +554,17 @@ - (void)getAppVersion:(CDVInvokedUrlCommand *)command {
|
546 | 554 | }];
|
547 | 555 | }
|
548 | 556 |
|
| 557 | +- (NSString*)getAppScheme { |
| 558 | + NSDictionary* settings = self.commandDelegate.settings; |
| 559 | + // Cordova |
| 560 | + NSString *scheme = [settings cordovaSettingForKey:@"scheme"]; |
| 561 | + if (scheme != nil) { |
| 562 | + return scheme; |
| 563 | + } |
| 564 | + // Ionic |
| 565 | + scheme = [settings cordovaSettingForKey:@"iosScheme"]; |
| 566 | + return scheme; |
| 567 | +} |
| 568 | + |
549 | 569 | @end
|
550 | 570 |
|
0 commit comments