apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 988 forks source link

[Question] cordova-ios 6.1 wkwebview localstorage migrate #979

Closed ikoshik closed 4 years ago

ikoshik commented 4 years ago

Hello! After update cordova-ios 5 to 6 we use wkwebview now So the question is it possible to migrate localstorage from webview to wkwebview? Tried to use https://github.com/MaKleSoft/cordova-plugin-migrate-localstorage but does not work. There is need to use plugin wkwebview...

breautek commented 4 years ago

It is possible, but it isn't something supported by Cordova itself.

The local storage files are simply a sqlite database with the following naming scheme: <scheme>_<origin>_0.localstrage

In the case of the UIWebView / using the file:// protocol, where it has no origin... the name would be file__0.localstorage

If you're migrating from UIWebView to WKWebView, that plugin should work, however some modifications needs to be applied.

  1. Inside plugin.xml, the <dependency id="cordova-plugin-wkwebview-engine" version="^1.1.0" /> line needs to be removed.
  2. If you want to use schemes (which I would personally recommend), then not only does the sqlite needs to be moved into a new folder, the filename needs to be named using the naming scheme above. The default scheme used is app://localhost, which would make the local storage file name be app_localhost_0.localstorage

Below doesn't target you, but in case it helps someone else...

If you're migrating from WKWebView to a scheme, then you can probably look at this fork I have, which migrated WKWebView file protocol to ionic webview scheme.

Because we use github for issues, I'll close this issue. But don't hesitate to join our slack if you require further assistance.