iOS wont delete my App Data after uninstall of MAUI Application - ios

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.

Related

Application UUID changes with app update in iOS

I am storing path of downloaded file in sqlite db and when I update the app, its UUID changes but data doesn't get moved to new container. So the path is essentially invalid now. I checked if files still exist using iExplorer and they do.
platform.Is("iOS"){
this.localdirectory = this.file.dataDirectory+filename;
}
else
{
this.localdirectory = this.file.externalDataDirectory+filename;
}
A better approach to store UUIDs that need to be persistent between App installs would be to use the Keychain.
The keychain will not only persist between updates - but also between app installations. In fact - you can even remove the app altogether and it's still there.
Only completely setting up the device from scratch will actually give you a new value.
There is a gotcha (depending on how you build you Keychain domain) that different Provisioning profiles might get a new keychain (but old one still remains).
I do suggest using an open source to manage the keychain itself btw. It's really ... how should I put it ... different than a lot of modern code and conventions.
Also note - you can even use iCloud keychain in case you want to share across devices , and Appgroups to share among apps on the same phone.

Offload App remove what in iOS 11

I just installed iOS 11 beta and I noticed that Offload App, By offloading app what will be remove Shared Directory or User Default or remove both or other than this ?
Looking for suggestions.
Thanks
Offloading lets you ”offload” the bundle (.ipa) for your app to save disk space. It will delete the ipa file (which contains your libraries and resources) and store only Documents and Data that includes shared data, UserDefaults etc..
Once we offload the app, what remains is the app icon of it with a small download pip on it to indicate that it has been offloaded .
Just by simple tapping on it, the app will get downloaded from the store and the saved Documents and Data will be integrated to the downloaded app, instead of an empty directory as it normally would with a fresh install.
This is a really great feature by Apple especially for devices with just 16GB storage. As you can see offloading the Prisma app saves me 44MB which is great. And even more, iOS can automatically offloads unused apps for us.
There is no official document(technical) available for offloading apps till the date but as the description(in setting app) says that your documents and data will be saved then I think it will save user defaults , document directories and core data - I mean all kind of data that can be stored!
It will save Shared Directory & User Defaults. Everything else will be deleted.

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.

Marmalade SDK - How to make data persistant after update

How do I keep the users data when they get an update.
I use the Marmalade SDK to develop an app and I saved the user data to bin files and text files, I used the ram:// prefix when saving the files.
If I delete the app and get it from the app store again with the could symbol It had lost all its user data. I would like to release an update that doesn't delete the users data. The app does not come with any user data files, the app creates them as you use it.
Edit: Marmalade is cross platform but my question is for iOS only and the app has been publish, I am asking with respect to an existing app.
Deleting the app from the device, also removes it's sandbox. So any user data stored locally is deleted. This is expected behaviour.
If the user data comes from the web, then you just need to download it again.
Have you read the tutorial for dealing with files?
I have never used that sdk but:
rom for the read-only portion of your apps data area and is read only.
ram for the writable portion of your apps data area. This drive is the only drive that is guaranteed to exist across platforms
rst for a removable memory card on the phone or tablet
raw for paths that will be passed directly to the underlying operating system without modification. (not supported on all platforms)
tmp for a system temp folder, outside of the s3e data area. (system temporary folder and currently only available on iOS)
So maybe you could try rst:// and get the expected result?

How to clear user data associated with an app

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)

Resources