Ankit Babbar
Ankit Babbar

Reputation: 101

Uninstall ReactNative App - Clean User Data

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

Upvotes: 7

Views: 8270

Answers (2)

Alex Shul
Alex Shul

Reputation: 500

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
    }
}

Upvotes: 0

Chris Geirman
Chris Geirman

Reputation: 9684

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.

  1. If your app is running, you can listen for UIApplicationWillTerminateNotification (see Detect iOS application about to delete?)
  2. Use the push notification feedback service (see Delegate Method when Deleting App)

Upvotes: 2

Related Questions