Incomplete data was retrieved from the localStorage

I am currently in the process of developing a mobile application using Phonegap version 1.4.1. I have encountered an issue on iOS (running on version 5.1) where the app fails to load all data from localStorage.

Upon first use of the app, I set a flag in localStorage like this:

window.localStorage.setItem("myFlag", "true");

Additionally, I set items "ItemA", "ItemB", and "ItemC" in a similar manner. These key/value pairs are added at different points during app usage, so their order of setting is not predetermined.

The issue at hand:

Upon reinstalling the app without deleting the current copy first, the app no longer recognizes "MyFlag", "ItemB", or "ItemC" - however, it does still recognize "ItemA". When checking window.localStorage.length, it returns 1 instead of the expected 4. I have exported the app's data files and inspected the file__0.localstorage with SQLite Inspector (available on the app store), which displays all four key/value pairs.

Due to iOS 5.1+ relocating local storage to the Cache folder, I have incorporated a backup procedure for the file__0.localstorage as outlined here. Essentially, this process involves copying the localstorage database to the Documents folder upon app pause or exit, and then reverting it back to the Cache folder when webViewDidStartLoad is executed. This backup mechanism is functioning correctly, leading me to believe that it is not the cause of the problem (as the symptom was present prior to implementing this procedure).

Answer №1

After discovering an issue with Cordova (Phonegap), it was found to be related to a bug that was reported here. The problem stemmed from Apple relocating the file__0.localstorage file to the Cache directory and a bug in Apple's software that changed the Bundle ID when upgrading an app version, without updating certain .plist file entries.

An attempted solution, outlined as an attachment here, required additional steps due to references to CDVInvokedUrlCommand and JSONKit. It was necessary to download updated versions of these files from the Cordova GitHub repository. Additionally, an error was found in the README.txt file of the proposed fix for Phongap 1.4.1:

6) In your app's "AppDelegate.m", replace your "webViewDidStartLoad" function with this:

    - (void) webViewDidStartLoad:(UIWebView *)theWebView 
    {
        static CDVLocalStorage* localStorage = nil;
        if (localStorage == nil) {
            localStorage = [[CDVLocalStorage alloc] initWithWebView:theWebView];   
            [localStorage restore:nil withDict:nil];
        }

        return [ super webViewDidStartLoad:theWebView ];
    }

The instructions should have advised adding the above method content to the existing method with the same signature, and correcting the line

[localStorage restore:nil withDict:nil];
to [localStorage restore:nil]; as per the actual method signature in use.

It was also important to ensure proper imports were included in AppDelegate.m.


For those who can update to the latest Phonegap version, that would be the simplest resolution. However, our situation involved using the older 1.4.1 version along with a plugin incompatible with newer Phonegap releases, making this modified fix the most suitable option for us.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending an object to a Vue 2 component and confirming its validity

I am working with a Vue component that has numerous props. <Field v-for="field in fields" :key="field.name" :name="field.name" :type="field.type" :label="field.label" :values="field.values" :value ...

Leveraging the power of Bootstrap and JavaScript to implement a custom Toast feature

I am utilizing Bootstrap 4 to design Toasts, and I am presently developing a JavaScript function to generate a toast. My attempt to create elements within the JS file did not properly style it. index.html <!doctype html> <html lang="en"> ...

The sorting feature for isotopes is malfunctioning following the addition of a new div element

Isotope was utilized for sorting divs based on attribute values, however, a problem arises when a new div is added or an existing div is edited. The sorting functionality does not work properly in such cases, as the newly created or edited div is placed at ...

Is it possible to import a class from a different project or module in TypeScript?

I am attempting to modify the build task in Typescript within this specific project: https://github.com/Microsoft/app-store-vsts-extension/blob/master/Tasks/app-store-promote/app-store-promote.ts I am looking to incorporate an import similar to the one be ...

Different ways to modify the color and thickness of a variable in HTML5 with either JavaScript or CSS

I am currently working with a JavaScript file where I have a variable defined as follows: var nombre = document.getElementById('nombre').value; The 'nombre' variable corresponds to an element in an HTML file: Nombre: <input type=" ...

Match rooms using Socket.io

I am utilizing the opentok and socket.io packages in an attempt to establish 2 distinct "groups". Successfully, I have managed to pair up individual users in a 1-to-1 relationship. However, my goal is to create two separate groups of users. For instance, ...

Fade in images using jQuery

I am having issues with fading in and out images using jQuery, it doesn't seem to be working as expected. I think there might be something crucial that I am missing. Take a look at the script below: var count = 1; setInterval(function() { ...

Error encountered when attempting to establish a connection between socket.io and express: network error

Similar Question: socket.io: Failed to load resource I'm having trouble getting a simple express + socket.io hello world app to work. I keep receiving the following error: "NetworkError: 404 Not Found - http:// localhost:3002/socket.io/socke ...

What is the best way to test the validity of a form while also verifying email availability?

I am currently working on implementing async validation in reactive forms. My goal is to disable the submit button whenever a new input is provided. However, I am facing an issue where if duplicate emails are entered, the form remains valid for a brief per ...

The submission feature for the textarea in Javascript is not functioning properly

As someone who is new to frontend development, I am currently facing a challenge with debugging JavaScript code that involves making changes to the content of a textarea. Despite my efforts to debug using the browser console, I have yet to identify why it ...

AngularJS Filter without creating a new object

Within my code, I am dealing with an array of objects that contain sub-objects. This particular array is utilized in an ng-repeat to display data in a table format. To illustrate, consider the following example: device { "name": "computer" ...

Getting the environment variable from Rails in your JavaScript: A guide

I am currently working on implementing a key system within my application. In the code I am using, there is logic that looks like this: $('.key-test-button').on('click', function(){ if ($('.key-test-input').val() === "MYK ...

AngularJS - A pagination demonstration incorporating intelligent logic inspired by Google's approach

I struggled to implement a paging solution that I came across online. The issue seems to be related to the timing of function calls, specifically how the setPage function is triggered before all data is retrieved, causing it to not properly determine the t ...

The functionality of window.localStorage.removeItem seems to be malfunctioning when used within an $http

Currently, I am sending a post request to my web service and upon successful completion, I am attempting to remove a token from local storage. Here is the code snippet: $http.post("MyService/MyAction").success(function (res) { if ( ...

ng-options encounters duplicate data when using group by in Internet Explorer

The dropdown menu that lists states works fine in Google Chrome, but duplicates groups in Internet Explorer. In Chrome, there are 2 groups, but in IE there are 4. How can I fix this issue in IE as well? Thank you. Here is the code snippet: <!DOCTYPE h ...

Can GET or POST variables be transmitted to external JavaScript?

Is it possible to pass a variable to an external JavaScript file? For instance: Suppose I have the following code: <script type="text/javascript" src="gallery.js"></script> I'm curious to know if it's feasible to pass an argument ...

What causes the fixed div to appear when scrolling horizontally?

I have replicated this issue in a live example: http://jsfiddle.net/pda2yc6s When scrolling vertically, a specific div element sticks to the top. However, if the window is narrower than the wrapper's width and you scroll horizontally, the sticky elem ...

Is it more suitable for a library used by getStaticProps to be classified as a normal dependency or a dev

When working with NextJS's getStaticProps, I am implementing a library that is only utilized during build time. Should this library be categorized as a regular or development dependency in my package.json? ...

Tips for achieving seamless scrolling with the combination of javascript and css

Looking for a solution to achieve smooth scrolling on an HTML page without using the #id_name to scroll to a specific div. Instead, I want to scroll to a particular point, such as having a button that scrolls down the webpage smoothly by 250px when press ...

Error encountered while attempting to import the mongoose npm module into a React application

I'm encountering an issue in my React project where I am trying to include an npm module within a component. Here's an example: var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test', {useNewUrlParser ...