Migrate localstorage from Canvas+ to WebView


#1

(Construct2) I need to migrate my app from Canvas+ to Webview. The challenge is getting localstorage data to migrate with it.

I have a workaround on this for Android but not for iOS. Has anyone done this?

I’ve looked at 3 solutions:

  1. The cordova-plugin-nativestorage plugin looks like a great method, but I can’t get it to read/write. Reads come up with “0”. Tracking this on another forum.

  2. Cloud storage or Firebase would be options, but Canvas+ doesn’t support them out of the box due to limited DOM access.

  3. (works on Android!) I can spawn a Webview instance from Canvas+ using Cocoon.App.Webview and pass localstorage.setitem commands for myuserdata keys. if I then upgrade the app to a Webview version and try localstorage.getItem (via browser.ExecJS), I see the data I created in Canvas+! So, this works! Buuuut… only for an Android. iOS Webview (UI or WK) doesn’t see anything created in localstorage before upgrade.

Any interesting thoughts on this?
Thanks, -Steve


#2

Hi Steve,

I had the same problems a few years back.
I can remember that I did it with WebStorage.

So, make an update where you copy the localstorage to the webstorage.
Give it some time, so that enough user have updated their app, so that all data is in the WebStorage instead of the local storage.

Next step is to build a new version using WebView+. From this update you will copy the data back from WebStorage to LocalStorage.

This should work. You can easily try it.

Hope this helps.

Best,
Andy


#3

Thanks for your reply, Andy!

Are you referring to JS localStorage, or the deprecated C2 “Web Storage” object? If I plant a key/value using either of these methods in Canvas+ (and confirm the read), it seems I cannot read/find that key after upgrading the app to WebView+. So, I’m hoping you were indicating something else. Otherwise, maybe something has changed in C2 now.

Thanks! -Steve


#4

Hi Steve,

I mean the deprecated WebStorage. Even if it’s deprecated, it’s still working. So you can go the way over the webstorage.
Another option is to go over a CloudService (like firebase). But there is no plugin working for Construct and Canvas+ for now.

Yes, WebView+ and Canvas+ have “diffrent locations” to store their data. So you cannot access the data when you switch between those engines.

Best
Andy


#5

Thanks. I didn’t get much mileage from WebStorage but NativeStorage seems to be doing the trick now.