Async-storage: [iOS] AsyncStorage data persists after uninstalling and re-installing app

Created on 24 Apr 2020  Â·  18Comments  Â·  Source: react-native-async-storage/async-storage

Current behavior

Using the latest stable release (1.9.0), AsyncStorage items that are set persist after an iOS app is uninstalled and then re-installed.

Expected behavior

AsyncStorage should be completely clear after uninstalling/reinstalling an app. This is how the framework bundled AsyncStorage behaves, so one would expect the community version to function the same way. If this persistence is intentional, it should be documented (as far as I can tell there is nothing in the docs that would explain this behavior, but I might have missed something). Apologies if I am mistaken or if this issue has been reported already.

Repro steps

  1. AsyncStorage.setItem('someKey', 'someData');
  2. Uninstall iOS app
  3. Re-install iOS app
  4. const data = AsyncStorage.getItem('someKey'); // returns someData

Environment

  • Async Storage version: 1.9.0
  • React-Native version: 0.62.2
  • Platform tested: iOS 13.3
enhancement iOS macOS

Most helpful comment

Since we're storing data in Application Support directory, it's backed up by default.

We need a way to opt out from doing that. Going to work on that in upcoming days

All 18 comments

Interesting. I did just a quick check (init new app, add AsyncStorage, save data, removed app, installed again, read data) and the data is indeed removed.
Are you using real device or simulator?

I have the same problem on IOS simulator when i'm using React Native Debugger. If i disable debug mode, all is fine.

My issue was on simulator as well (XCode 11.3)

I have this problem using expo 37 + react native 61.4.

Can anyone provide a project where issue is reproducible ?

I've run into this as well on a physical iOS device, using:

"@react-native-community/async-storage": "^1.11.0",
"react-native": "0.62.2",

Project repo is private, but I can provide more details upon request. App name is Serenity: Guided Mental Health.

@JacquesLeupin Please do include some repro steps, thanks!

How can we maintain this behaviour? I have a scenario where it's imperative that the data in AsyncStorage can be persisted across uninstalls/reinstalls. This is because a unique device ID is stored within it.
I read that iCloud will backup the data and can recover it when reinstalled, and the same for Android with the Play Store. Is that true?

@developius maybe storing your device id in keychain solve your problem.

I also think that clearing data after app uninstall is important to avoid accumulation of garbage...

@JacquesLeupin were you able to fix this?

@nishanttatva nope, i never found a fix for this issue.

our app uses firebase for auth, and we refactored to avoid storing most data in AsyncStorage. to automatically log out a user, we implemented this workaround.

@exotexot good call, thanks!

Since we're storing data in Application Support directory, it's backed up by default.

We need a way to opt out from doing that. Going to work on that in upcoming days

@Krizzu

We need a way to opt out from doing that. Going to work on that in upcoming days

Were you able to find anything?

We also need this fix as it causes problems when users try to uninstall/reinstall (particularly noticeable when trying to experience a First-App-Launch experience)! This is a pretty urgent issue for our Application, so I'd love to help.

There's a filesystem flag that can be set on files to enable/disable this type of behavior on iOS.

@Krizzu do you need any help getting a solution for this?

From an API perspective @Krizzu, what did you want for this? Solutions that come to mind:
A. a standalone global flag that users could attach to RN.AsyncStorage -- RN.AsyncStorage.setBackupMode("no-restore")

  • users could setItem with a magic key: __ASYNC_STORAGE_BACKUP_MODE__ = "no-restore"
  • Change this from a Singleton-type API where there's only 1 Storage "Domain" to multiple storage domains + add an API to configure behavior for each domain. -- This would be multiple files on disk, and users would need an API to get "other" storage domains. -- This would be the biggest API enhancement, but it could be backwards compatible…

@fbartho

I've created an initial PR that has backup feature toggling. I cannot repro this myself, so it'd be great if you (or anyone else) could give it a try.

Regarding using that feature - I thought about adding an entry to package.json like AsyncStorage where we'd keep all the feature flags (for Android too). We'd have to find a way to read it on AppLaunch (where AsyncStorage init is happening).

@Krizzu we'd be happy to try a beta build that has the final implementation of your proposed feature -- I've commented on your PR for now with some further thoughts. This is affecting our app in production, so we're comfortable testing an appropriate beta build in our normal QA process.

Hello what is the status of this? It is interesting one IOS app is storing values correctly, and store is not persisted on reinstall. Another app the values are persisted on reinstall, so I'm wondering is it due to the fact "On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files." That maybe this second app has larger values and is getting stored in a different place in the system? We are running into issues with this so I'm wondering the status.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

santhanakrishnanstark picture santhanakrishnanstark  Â·  67Comments

Alaa-Ben picture Alaa-Ben  Â·  20Comments

hms111111 picture hms111111  Â·  24Comments

while-it picture while-it  Â·  51Comments

loic-lopez picture loic-lopez  Â·  37Comments