11#if defined(__has_include)
22#if __has_include("CDVWKWebViewEngine.h")
33
4+ #import < Cordova/NSDictionary+CordovaPreferences.h>
45#import " CDVWKWebViewEngine.h"
56#import " CodePush.h"
67
@@ -16,6 +17,11 @@ - (id)loadRequest:(NSURLRequest *)request {
1617 lastLoadedURL = request.URL .absoluteString ;
1718 NSURL *readAccessURL;
1819
20+ NSURL * bundleURL = [[NSBundle mainBundle ] bundleURL ];
21+ if (![lastLoadedURL containsString: bundleURL.path] && ![lastLoadedURL containsString: IdentifierCodePushPath]) {
22+ return [self loadPluginRequest: request];
23+ }
24+
1925 if (request.URL .isFileURL ) {
2026 // All file URL requests should be handled with the setServerBasePath in case if it is Ionic app.
2127 if ([CodePush hasIonicWebViewEngine: self ]) {
@@ -47,6 +53,36 @@ - (id)loadRequest:(NSURLRequest *)request {
4753 }
4854}
4955
56+ - (id )loadPluginRequest : (NSURLRequest *)request {
57+ if (request.URL .fileURL ) {
58+ NSDictionary * settings = self.commandDelegate .settings ;
59+ NSString *bind = [settings cordovaSettingForKey: @" Hostname" ];
60+ if (bind == nil ){
61+ bind = @" localhost" ;
62+ }
63+ NSString *scheme = [settings cordovaSettingForKey: @" iosScheme" ];
64+ if (scheme == nil || [scheme isEqualToString: @" http" ] || [scheme isEqualToString: @" https" ] || [scheme isEqualToString: @" file" ]){
65+ scheme = @" ionic" ;
66+ }
67+ NSString *CDV_LOCAL_SERVER = [NSString stringWithFormat: @" %@ ://%@ " , scheme, bind];
68+
69+ NSURL * startURL = [NSURL URLWithString: ((CDVViewController *)self .viewController).startPage];
70+ NSString * startFilePath = [self .commandDelegate pathForResource: [startURL path ]];
71+ NSURL *url = [[NSURL URLWithString: CDV_LOCAL_SERVER] URLByAppendingPathComponent: request.URL.path];
72+ if ([request.URL.path isEqualToString: startFilePath]) {
73+ url = [NSURL URLWithString: CDV_LOCAL_SERVER];
74+ }
75+ if (request.URL .query ) {
76+ url = [NSURL URLWithString: [@" ?" stringByAppendingString: request.URL.query] relativeToURL: url];
77+ }
78+ if (request.URL .fragment ) {
79+ url = [NSURL URLWithString: [@" #" stringByAppendingString: request.URL.fragment] relativeToURL: url];
80+ }
81+ request = [NSURLRequest requestWithURL: url];
82+ }
83+ return [(WKWebView *)self .engineWebView loadRequest: request];
84+ }
85+
5086#pragma clang diagnostic pop
5187
5288// Fix bug related to unable WKWebView recovery after reinit with loaded codepush update
0 commit comments