Data does not cleared in ionic storage


#1

I have used ionic storage in my app. Also, I store token in storage while authenticating. But when I uninstall the app, the ionic stoarge is not getting deleted, and when I install it again the app is logged in with the previous user x, I experiencing this issue in some devices (Nexus, Redmi Note 3), whereas some other devices are not able to replicate this issue such as moto e.

Please suggest how to forcefully clear the ionic stoarge on uninstalling the app.


#2

For Clearing Ionic Storage data of your app Programmatic I hope you tried Clear Method for Ionic Storage.

But to clear Application’s data in the device while uninstalling, you need to clear application data from the settings option in the whichever device you are using
In your device go to Settings >Apps >YourApp and hit the button Clear Data in order to clear data while uninstalling your Application.


#3

Yes, I do have logout method where I have used storage.clear() method. but while uninstalling it won’t be called(assuming user unistall app without logout the app), so that the data from the storage is not cleared.

Manually data clear is not a solution, I need something that I will handle in code.


#4

What you are experiencing is not not deleted data, but automatically restored data on reinstall of your app. iOS and Android started to back up local storage data to their cloud services a few versions ago.

Lucky for you, this can be configured in Cordova.

For iOS:
https://cordova.apache.org/docs/en/dev/config_ref/index.html (Search for “BackupWebStorage”)

For Android:
http://stackoverflow.com/questions/30527107/how-to-add-androidallowbackup-true-via-cordova-plugin
https://github.com/AlexandrSalin/cordova-android-plugin-allow-backup
https://www.simonmacdonald.com/blog/2017/4/13/cordova-plugin-allow-backup (Note the “UPDATE” at the bottom of the post)

(Please report back if you make it work, the Android solutions still seem a bit rough)


#5

Thanks for the help :slight_smile: It’s worked for me. But strangely solution for iOS also applies to android.


#6

What did you set it to? I have my BackupWebStorage set to none and it still seems to be getting backup in the cloud for Android. What version of Ionic and Cordova were you using?


#8

In addition to the above - if you run into unbound prefix error,
add the namespace for Android to the widget tag

 xmlns:android="http://schemas.android.com/apk/res/android" 
<widget CFBundleShortVersionString="1.0.0" android-versionCode="65" android-versionName="1.0.0" id="com.mydomain.app" ios-CFBundleVersion="1.0.0.55" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
 <platform name="android">
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
        </edit-config>
</platform>

open issue here: https://github.com/mhartington/cordova-config-utils/issues/16