How to clear user data associated with an app - ios

On the simulator, Reset Content and Settings... will clear all apps and data.
I would like to clear out all the data used by the app I'm developing without wiping the entire phone. Note that uninstalling the app (by wiggling and pressing the x button) does not seem to wipe the data as when I reinstall the app, some settings are still persisted.

There are 2 places outside of the app's sandbox directory where settings are saved: User defaults and the keychain. User defaults get completely erased when the app is deleted. If the app you are using saves to the keychain, you should delete all the key/value pairs you might have saved. That should do it.

i am not 100% on this but for the iPhone simulator how about just going to the following folder location
/Users/{insert_your_username}/Library/Application Support/iPhone Simulator/{simulator_version}/Applications/
and then delete the appropriate folder here (just browse one level deeper into those 32-character-long folders to identify which application settings it holds)

Related

iOS wont delete my App Data after uninstall of MAUI Application

I am using MAUI.Essentials to store data in secure storage.
SecureStorage.SetAsync(key, securedValue);
But uninstalling the Application in android is deleting app data but the same is not working in iOS.
According to this post we need to turn off the backup in iCloud.
I am currently testing in iPhone simulator and under settings I have not logged in to iCloud.
Also I tried below code to manually delete the app data
if (VersionTracking.IsFirstLaunchEver)
{
services.AppCache.Clear();
}
But I don't want to delete it manually.
Any help is appreciated!
Given that (by iOS design) there isn't any way to delete data from iOS secure storage when app is deleted, you'll want a way to detect that there is "obsolete" data there, if the app gets deleted then re-installed.
When you detect this, you can decide whether to ignore or delete that "obsolete" data, so that it isn't visible to the new installation. Thus, it is as if it was not kept (other than the slight waste of storage -- never put anything large into secure storage).
I do this by creating an empty file in app local (not secure) storage, at the same time as saving the data to secure storage.
When app starts up, I check if that empty file exists. If it is not there, then I know anything in secure storage is "obsolete", left over from a previous install of app, so I erase it (if I don't want it to be visible when re-install).
Note that this also handles the case where user goes to Settings, finds the app, and does "Delete Data". Even if they don't uninstall app, the next time it runs, it will act as if it is a new install.
In the Maui official document (Secure storage) wrote:
KeyChain is used to store values securely on iOS devices. The
SecRecord used to store the value has a Service value set to
[YOUR-APP-BUNDLE-ID].microsoft.maui.essentials.preferences.
In some cases, KeyChain data is synchronized with iCloud, and
uninstalling the application may not remove the secure values from
user devices.
You can try to turn off iCloud with a real device, iCloud cannot be used in the simulator. You also can let the app start to call the delete code in your question to determine whether it is the first installation to delete the data in the KeyChain.

can the user delete the NSUserDefaults setting, like android's sharedPreferences?

Is a simple question but I only found that you can delete the NSUserDefaults settings via code.
I need to know if the user can delete the NSUserDefaults settings like in Android you can go to the app's configurations and delete the app's data.
Thanks : )!
I need to know if the user can delete the NSUserDefaults settings like in Android you can go to the app's configurations and delete the app's data.
Yes, the user can easily do this - by deleting the app from the device. (The user holds down the Home button until the app icons in the springboard "jiggle", and then taps the "X" at the corner of an app icon.) This removes the app's sandbox, and the NSUserDefaults is a file in the sandbox and is destroyed along with everything else.
If the user then reinstalls the app, it gets a fresh start - as far as the NSUserDefaults is concerned.
(Other, system-level "memories" about this app are not necessarily forgotten merely because the user deletes the app.)
From an end-user flow, deleting the app or going into Settings > General > Reset All Settings effectively deletes any locally saved data for an iOS app, I believe.

iOS Data Protection not working on already installed app

I want to turn on 'Data Protection' in my app. Also, I wanted to check whether it is working with existing apps since I did not use it initially. To test this I used developer provisioning profile. First I installed the previous app (DataProtection is off) in my pass code enabled device and made sure that user's documents are available in the Documents folder. Then I turned on Data Protection in my provisioning profile and rebuilt the app using that new profile. Then I installed it on top of the previous app. Then I locked the device and downloaded the app sandbox using Xcode and noticed that I can access sandbox without any problem. I did it several times, but sandbox is still accessible.
Then I deleted the app and freshly installed the app that I had Data Protection turned on. Then I downloaded the app sandbox and I noticed that all folders in the sandbox including Documents folder are empty.
That means Data protection working only on freshly installed app. Am I doing anything wrong? I want to turn on Data Protection on my existing apps as well. How can I achieve this?
Since I didn't get enough attention to this question I posted it to apple developer forum. What they suggest was after enabling data protection If We are going to update the app (without deleting old app) we should explicitly set data protection for all files including old ones.
So what I did was loop through my document folder and set data protection attribute to all my old files.
Also I set data protection attributes in all places where I create new files. That solves my problem.
So the bottom line is If you are going to enable data protection in your old app better to do it explicitly.

Is there a way to not erase the documents directory when uninstalling the app?

I'm developing an AIR app for iPad, and I found that when I uninstall the app, the documents directory data gets erased, is there a way to keep this data even when I delete the app or this behavior is regulated by iOS and there is nothing I can do about it?.
Thanks.
No you cant
From The iOS Environment
For security reasons, iOS places each app (including its preferences and data) in a sandbox at install time. A sandbox is a set of fine-grained controls that limit the app’s access to files, preferences, network resources, hardware, and so on. As part of the sandboxing process, the system installs each app in its own sandbox directory, which acts as the home for the app and its data.
So you delete the application all the content regarding that particular app gets deleted.
as soon app get uninstalled the document directory folder also get deleted with that. Although you will not able to access that folder from other apps so there is no need to keep that.

Do app updates overwrite the app's home directory?

I use the NSHomeDirectory() function to get the app's home folder, and write to the Documents directory within that. I'm curious, though, what happens when the user downloads an update for the app from the App Store? Will it all be deleted? When I delete the app on the device, then reinstall it, it's wiped out. So, I'm curious to know what will happen with an update. I can't find this in the documentation at all.
Stuff inside ~/Documents/ and the user preferences are preserved during update.
See the iOS File System Programming Guide.

Resources