Skip to content

Commit e310085

Browse files
authored
Merge pull request #248 from liammazy/master
fix: Unsupported URL issue on Ionic WKWebView
2 parents ae3ed9a + 6355aa7 commit e310085

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/imgcache.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,22 @@ LOG_LEVEL_ERROR = 3;
175175
return (Helpers.isCordovaAndroid() && device.version && (device.version.indexOf('2.') === 0 || device.version.indexOf('3.') === 0));
176176
};
177177

178+
// special case for #223 #237 #246
179+
Helpers.ionicNormalizer = window.Ionic &&
180+
((window.Ionic.WebView && window.Ionic.WebView.convertFileSrc) || window.Ionic.normalizeURL);
181+
182+
// check if ionic webview convertfilesrc function exist
183+
Helpers.isIonicNormalizerFunctionExist = function() {
184+
return (typeof Helpers.ionicNormalizer === 'function');
185+
};
186+
178187
// Fix for #42 (Cordova versions < 4.0)
179188
Helpers.EntryToURL = function (entry) {
180189
if (Helpers.isCordovaAndroidOlderThan4() && typeof entry.toNativeURL === 'function') {
181190
return entry.toNativeURL();
182-
} else if (typeof entry.toInternalURL === 'function') {
191+
} else if (
192+
!Helpers.isIonicNormalizerFunctionExist() && // Fix for #223 #237 #246
193+
(typeof entry.toInternalURL === 'function')) {
183194
// Fix for #97
184195
return entry.toInternalURL();
185196
} else {
@@ -190,7 +201,9 @@ LOG_LEVEL_ERROR = 3;
190201
// Returns a URL that can be used to locate a file
191202
Helpers.EntryGetURL = function (entry) {
192203
// toURL for html5, toURI for cordova 1.x
193-
return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());
204+
var url = (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());
205+
// Fix for #223 #237 #246
206+
return Helpers.isIonicNormalizerFunctionExist() ? Helpers.ionicNormalizer(url) : url;
194207
};
195208

196209
// Returns the full absolute path from the root to the FileEntry

0 commit comments

Comments
 (0)