Reputation: 291
Brief overview of the app: We had two(IOS Cordova & IOS native) working apps, We had a plan to integrate both the application with existing technical stack. We managed to Integrate successfully by converting the Cordova app into binaries with the help of cocoapods and integrated it into IOS native app, the app functionality is working fine.
In IOS native app we have more than one webviews.
Issue : In Cordova app sometimes we are loosing the data which is saved using "window.localStorage" this issue is not consistent but happens 2or3 out of 10 tries .
Above issue Occurs only in the Integrated version of app (Cordova + Native) and not in stand alone version of Cordova app.
We had the same kind of issue in integrated version (Android native + Cordova android) we managed to fix this issue by overriding the "windows.localstorage" using "addJavascriptInterface"
Questions : 1) Have anyone experienced the loss of localstorage value. 2) Do we have such option( ie "addJavascriptInterface" ) for IOS as well if so can you please explain how or can you suggest some other better option to commute between Cordova webview to the native layer
Note :This commute from Cordova webview to native IOS should be synchronous not asyn because I need to override the "windows.localstorage" Used cordova version 3.6.3
Thanks in advance
Upvotes: 1
Views: 2429
Reputation: 291
After deep-diving into the issue we managed to find out that the localstorage file is getting corrupted which result in loss of persisted data.
Solution which worked for us is : We started backing up the localstorage file via native layer of iOS. In our app we face this issue only when user navigate from Native stack to hybrid stack as the Native stack will always be the starting point of user`s transaction.
Note : We had integrated the Cordova app ( Cocoapods ) into Native app.
Upvotes: 0
Reputation: 403
Since iOS 5 the localstorage is not persistent. The file of the localstorage is saved in the directory .../Library/Caches and this directory may be deleted by the OS if the system is very low on space. For more information about the file system in iOS see: File System Programming Guide
According to the documentation of cordova they mention the loss of data as a disadvantage of the localstorage: "iOS stores localStorage data in a location that may be cleaned out by the OS when space is required."
So in case you're running out of space the loss of data is not a bug.
Because of this problem we are looking for an alternative to localstorage, too.
After researching I've found a plugin especially for this problem. This plugin is using NSUserDefaults (iOS) and SharedPreferences (Android) to store the data permanently. This is actually my preferred solution for this problem.
Other ways out of this problem, that are suggested often are:
Upvotes: 2
Reputation: 11
I had faced same issue with some devices. There is one model out of about a dozen that we use that has similar issue. I store 6 objects (strings) in local storage and on these devices some of objects in unexpected moment may become null.
After digging stackoverflow I have found some similar cases that do not unambiguously answer the issue. For example, they reported:
So, there are no answers for me yet.
My own plan — to use files or SqlLite. I am sure that files that are stored with FileAPI are there and are not lost.
Upvotes: 0