Telerik-Verified-Plugins / WKWebView

DEPRECATED - this plugin served a purpose in the past, but there are better implementation now

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Localstorage sometimes wrong

mbaeurle opened this issue · comments

If port 12344 is ever in use when the app is (re)started, the wkwebview plugin will move on to port 12345, see startServer() in AppDelegate+WKWebViewPolyfill.m.

As the port number is used in the name of the copy of the localstorage, confusion starts if the port number is ever changed.
Effects seen by customers are no stored data in the app at all or the app is not continuing with the data from the last run, but using the localstorage from the run before, thus forgetting changes that the user has made.

Proof that this can happen is the existence of both /Library/WebSiteData/http_localhost_12344.localstorage and /Library/WebSiteData/http_localhost_12345.localstorage that I have seen on a customer's iPhone.

See copyLS() in MyMainViewController.m, which has this comment:
// TODO if the app is ever launched on a different port.. LS can't be loaded -- not worse than the previous implementation, but still
// TODO use the port, luke!

But it's not clear to me, what is the idea behind using the port in the file name in the first place?

Tests with iOS 10 Beta indicate that this is occurring quite frequently on iOS 10. I haven't been able to view any files/logs so far because iExplorer can't read iOS 10 devices yet.

This is a serious problem anyway because users may be getting wrong data, even though this only happens rarely. If this is more frequent on iOS 10 then it will be even more of a problem in the future.

I'm seeing the same problem on iOS 10 with localstorage not being loaded at all. Not sure what is going on there.

One workaround that I'm starting to work on is to use the iOS keychain to store settings, or https://github.com/apla/me.apla.cordova.app-preferences

In addition your issue @mbaeurle, iOS10 local storage will no longer store data between app launches. For now, I'd recommend the nativeStorage plugin, which works almost like a drop-in replacement for localStorage (it is async though, so you'll need to handle callbacks). Using nativeStorage will also resolve your issue.

commented

yip. I can confirm that. With iOS10 the localStorage seems to be cleared after the app restarts. I'm using IndexDB and WebSQL as an alternate storage-provider now.

https://github.com/localForage/localForage gives you a nice async API for this.

However the synchronous localStroage was a sleek way to store some sort of key/value -data with less effort. Looking forward to get this working again.