I want to clean the User AuthData Saved in Mobile upon uninstall. AuthData is saved using AsyncStorage. Is there any mechanism by which I can detect App Uninstall in ReactNative
Asked
Active
Viewed 7,450 times
7
-
1The AsyncStorage saved by your application should be automatically cleared upon app uninstall, at least on iOS. I am not sure what the behavior is on Android. – jevakallio Apr 24 '16 at 11:41
-
1Are you sure about that @jevakallio? My understanding (and I could be totally wrong) is that AsyncStorage data is available across apps, which is why best practice is to namespace your keys with something like `@AppName:key`. Here's an excerpt I pulled from the book *Learning React Native*, "The storage key used by AsyncStorage can be any string; it’s customary to use the format @AppName:key, like so:" – Chris Geirman Apr 24 '16 at 12:16
2 Answers
2
Doesn't seem possible, especially if your app is not running at the time they uninstall. However, there seems to be a couple approaches you can take, but neither is perfect.
- If your app is running, you can listen for
UIApplicationWillTerminateNotification
(see Detect iOS application about to delete?) - Use the push notification feedback service (see Delegate Method when Deleting App)

Community
- 1
- 1

Chris Geirman
- 9,474
- 5
- 37
- 70
0
For me worked this solution (swift code): https://stackoverflow.com/a/40732677/3151214
Variable userDefaults (NSUserDefaults
) can be accessed through Settings
in React Native, so javascript implemetation can be looked like:
import { Platform, Settings } from 'react-native';
function getAuthData() {
let isStoreNeedCleaning = false;
if (Platform.OS === 'ios') {
if (!Settings.get('hasRunBefore')) {
Settings.set({ hasRunBefore: true });
isStoreNeedCleaning = true;
}
}
if (isStoreNeedCleaning) {
// Clean up your store
} else {
// Load auth data from store
}
}

Alex Shul
- 500
- 7
- 22