Kevin Amiranoff
Kevin Amiranoff

Reputation: 14503

Where does React-Native AsyncStorage save data on disk using iPhone Simulator?

Using IOS Simulator, where does React-Native AsyncStorage save the data on disk ?

I am using IOS Simulator version 10.0 and running IOS 10.2 and react-native 0.40.0

Upvotes: 7

Views: 7249

Answers (3)

Lior Tabachnik
Lior Tabachnik

Reputation: 148

If you prefer to see the AsyncStorage in console as i prefer

you can use this code :

export var getAllKeysAndValues = async () => {
  try {
    // Retrieve all keys
    const keys = await asyncStorage.getAllKeys();

    // Create an object to store key-value pairs
    const keyValuePairs = {};

    // Loop through each key and fetch its corresponding value
    await Promise.all(keys.map(async key => {
      const value = await asyncStorage.getItem(key);
      keyValuePairs[key] = value; // Store key-value pair
    }));

    console.log('All keys and values:', keyValuePairs);
    return keyValuePairs; // You can return the object if needed
  } catch (error) {
    console.error('Error getting all keys and values:', error);
    throw error;
  }
};

Upvotes: 0

chetstone
chetstone

Reputation: 670

Based on the other helpful comments and answers, let me summarize how to inspect AsyncStorage:

First, cd into the Async directory.

cd `xcrun simctl get_app_container booted $BUNDLE_ID data`/Documents/RCTAsyncLocalStorage_V1

Then review the manifest:

jq < manifest.json

Then to pretty-print a non-null value in the manifest:

jq '."somekey"|fromjson' < manifest.json

For null values, find the file that has the value:

md5 -s "otherkey"
# 90f5ba064f8280d4c94b1f0b1a85a79e

Then pretty-print that file:

jq < 90f5ba064f8280d4c94b1f0b1a85a79e

I have also shared this in a gist

Upvotes: 2

user2266462
user2266462

Reputation:

React Native async storage data is inside Documents folder of you application sandbox. For react-native 0.40.0 it is Documents/RCTAsyncLocalStorage_V1/manifest.json.

Path to sandbox folder for iOS Simulator (Xcode 8.2) is: ~/Library/Developer/CoreSimulator/Devices/{DEVICE_ID}/data/Containers/Data/Application/{APP_ID}

To find DEVICE_ID you can use xcrun simctl list from terminal. Since your application gets new APP_ID on each run, you can't easily find it. I simple list all files inside Application and get most recently updated. See Xcode 6 keeps renaming my app's directory in iOS8 simulator after each run. and related for other solutions.

Upvotes: 8

Related Questions