ionic-cache-src icon indicating copy to clipboard operation
ionic-cache-src copied to clipboard

WKWebView support

Open bojanvidanovic opened this issue 9 years ago • 4 comments

Has anybody managed to make this plugin work with wkwebview with local server?

bojanvidanovic avatar May 17 '16 16:05 bojanvidanovic

Any updates for WKWebView? it will give me error "Not allowed to load local resource"

jd0048 avatar Aug 18 '17 07:08 jd0048

@jd0048 Nope. I don't recommend you using it, it is out-dated at the moment.

bojanvidanovic avatar Aug 18 '17 08:08 bojanvidanovic

Hello guys! I'm using this lib for an Ionic app and it works fine on android. Today I started with iOS and I'm using cordova-plugin-ionic-webview. I fixed and I want to share with you.

You need to ionic-cache-src.js and search for:

case 'iOS':
  return $window.cordova.file.documentsDirectory;

change $window.cordova.file.documentsDirectory; to $window.cordova.file.documentsDirectory.substring(7);.

It should work. It's a simple hack but it works if you need something fast.

Why this works?

When accessing files using WKWebView, you can not use "file://". That's why I'm using substring(7) there(to cut off that part).

You can get a ref from here: https://ionicframework.com/docs/wkwebview/#rewriting-file

Hope this helps!

devfelipereis avatar Oct 17 '17 14:10 devfelipereis

@devfelipereis thanks a lot, you help me so much. An improved way to perform your fix is to change to this: window.Ionic.WebView.convertFileSrc($window.cordova.file.documentsDirectory);

julitroalves avatar Jul 30 '20 20:07 julitroalves