Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Compatibility with [email protected] #635

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/ios/CodePush.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import <Cordova/CDV.h>
#import <Cordova/CDVConfigParser.h>
#import <Cordova/CDVWebViewEngineProtocol.h>
#import <Cordova/NSDictionary+CordovaPreferences.h>
#import <WebKit/WKWebView.h>
#import "CodePush.h"
#import "CodePushPackageMetadata.h"
#import "CodePushPackageManager.h"
Expand All @@ -20,6 +22,8 @@ @implementation CodePush
NSDate* lastResignedDate;
NSString* const DeploymentKeyPreference = @"codepushdeploymentkey";
NSString* const PublicKeyPreference = @"codepushpublickey";
NSString* const IdentifierCodePushPath = @"codepush/deploy/versions";
NSString* lastLoadedURL = @"";
StatusReport* rollbackStatusReport = nil;

- (void)getBinaryHash:(CDVInvokedUrlCommand *)command {
Expand Down Expand Up @@ -407,12 +411,43 @@ - (void)loadURL:(NSURL*)url {
// 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]];
[self loadPluginRequest:[NSURLRequest requestWithURL:url]];
#else
[(UIWebView*)self.webView loadRequest:[NSURLRequest requestWithURL:url]];
#endif
}

- (id)loadPluginRequest:(NSURLRequest *)request {
if (request.URL.fileURL) {
NSDictionary* settings = self.commandDelegate.settings;
NSString *bind = [settings cordovaSettingForKey:@"hostname"];
if(bind == nil){
bind = @"localhost";
}
NSString *scheme = [settings cordovaSettingForKey:@"scheme"];
if(scheme == nil || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"file"]){
scheme = @"app";
}
NSString *CDV_LOCAL_SERVER = [NSString stringWithFormat:@"%@://%@", scheme, bind];

NSURL* startURL = [NSURL URLWithString:((CDVViewController *)self.viewController).startPage];
NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
NSURL *url = [[NSURL URLWithString:CDV_LOCAL_SERVER] URLByAppendingPathComponent:request.URL.path];
if ([request.URL.path isEqualToString:startFilePath]) {
url = [NSURL URLWithString:CDV_LOCAL_SERVER];
}
if(request.URL.query) {
url = [NSURL URLWithString:[@"?" stringByAppendingString:request.URL.query] relativeToURL:url];
}
if(request.URL.fragment) {
url = [NSURL URLWithString:[@"#" stringByAppendingString:request.URL.fragment] relativeToURL:url];
}
request = [NSURLRequest requestWithURL:url];
}
return [(WKWebView*)self.webViewEngine loadRequest:request];
}


+ (Boolean) hasIonicWebViewEngine:(id<CDVWebViewEngineProtocol>) webViewEngine {
NSString * webViewEngineClass = NSStringFromClass([webViewEngine class]);
SEL setServerBasePath = NSSelectorFromString(@"setServerBasePath:");
Expand Down Expand Up @@ -488,7 +523,7 @@ - (void)redirectStartPageToURL:(NSString*)packageLocation{
if ([CodePush hasIonicWebViewEngine: self.webViewEngine]) {
[CodePush setServerBasePath:URL.path webView:self.webViewEngine];
} else {
((CDVViewController *)self.viewController).startPage = [URL absoluteString];
[self loadURL: URL];
}
}
}
Expand Down