LocalStorage not persistent when app is updated (cordova ios 3.8.0 -> 4.1.1) in iOS 10.2

I have a app built with cordova ios 3.8.0.
When I updated the app to new version which is built with 4.1.1 LocalStorage returns empty. I cannot retrieve the data saved by previous version.
Works in iOS 8 and 9
Does not work in iOS 10.2

Has anyone experienced this issue? Any ideas?

Please help.

Cordova-ios: current 4.1.1, previous 3.8.0
Cordova CLI: current 6.1.1
xcode: current 7.2.1

1 Like

you can use this

Problem is the app is already in app store and it uses localStorage.
The new version uses both LocalStorage and ios KeyChain. But we need to get saved user information (LocalStorage) from previous version.
I’ll update Cordova and check.
But my question is why it works in 8,9,10 and not in 10.2.

Tested with latest cordova version but issue exists
cordova cli: 6.5.0
cordova-ios: 4.3.1
This issue is reproducible in simulator as well.

I manually copied localstorage files from old location to new location and I was able get old local storage data
Old files

Copied to this location

I think Cordova does not copy old localstorage to new location after app is updated.
No idea why it behaves differently in iOS 10.2 only.
Can anyone please point me to the code where old local storage files are copied (in CDVLocalStorage)?
I really need to get this fixed.

HI Nirman,

I’m also facing same issue. Do you have solution for this issue.

1 Like

I am not sure if Cordova “copies” localStorage after an update - as I understood it this is pure iOS doing its thing. And localStorage sometimes gets lost.

If the upgrade of cordova-ios from one to another version is the cause then maye first do an update with the old cordova-ios version that saves the data a different way. When this is rolled out and enough users have it, do another update that goes to the new cordova-ios version. Won’t work for all users, but some.

Unfortunately I couldn’t find a solution for this.
iOS 10.2 definitely broke something in Cordova. But looks like it will be not fixed.

In our case, we came up with an alternative. All the user data is saved in our databases as well. So we wrote an new service endpoint mobile app can call and get data. Mobile app will call the endpoint if local storage is empty, and save data in Local Storage again.
Ideally Local Storage should be copied in case of an app update.
This issue occurred to me in Android too. In Android the update was crosswalk -> non crosswalk.

@nirman99 ,
Thanks for update, In my case localStorage is not sync with database (as per requirement). I tried WebSql also but facing same issue.

how have you fixes this problem? I have the same problem about persistence on iOS using ionic/storage

I was not able to get it fixed.
We save user data in servers as well. What I did was when opening the app, it calls back-end and get user data.

Options you can have:

  • Do not use local storage. Use something else like SQLite, File system. This is only If you do not have an app already in the app store

  • Try building with a different Cordova version

  • Sync app data If you have data in back-end servers

Ionic Storage should not have that problem. This is one of the reasons for its existence.