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

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.

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.

Camera and Photos permission - iOS [duplicate]

In my iOS app I am accessing the user's photo gallery. The first time the user does this, it asks them for permission. Some of my users have reported getting a crash this first time due to the permission request, but it works fine on subsequent tries.
To be able to test this on my own, I need to be able remove the permission from my iPad and have it prompt again. Is there a way to do this either through the iPad/iPhone itself or through code?
Run the Settings app. Go to General, then Reset. Tap on Reset Location & Privacy. This will reset all of your location and privacy settings, not just for your test app. But you are doing this on a development device so that should be OK. This works in the Simulator too.
In iOS 7+, you can go into Settings > Privacy > Photos and explicitly enable or disable access for individual apps.
This is much better than resetting your entire device privacy settings!
Another way is to temporary change Bundle Identifier (CFBundleIdentifier) in Info.plist.
System will treat such app as a new separate app and will display "would like to access your Photos" alert.
Don't forget to revert CFBundleIdentifier after you end testing.

iOS - letting another app edit and save files my app created, in the same folder where the file was opened from

I would like to know if it is possible to let another iOS app open a file my app has created and then the other app edits and saves it just in the original location where my app had saved it at creation time. Or, instead, are files opened with the NSUrl in UIApplicationLaunchOptionsURLKey just read-only so they just can be saved in the other app sandbox?
You can't edit other apps sandbox, it's private to your own app (except for the Documents folder, that a user can access from iTunes).
You also don't have access to the file system of the phone.
Welcome to iOS :)
The best way to achieve this is a custom URL scheme. The other option would be iCloud, but I think the URL scheme is the way to go here.
Edit I see the link doesn't work correctly, not sure why, just scroll the page down to the Communicating with Other Apps paragraph.

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)

iCloud KeyValueStore preference changes and handling them across various devices

As per Apple's guidelines my app provides an option for user to enable/disable storage in iCloud.
Use case :
By default the storage in iCloud is disabled
User downloads the app on iOS Device 1 and creates some files etc
User then downloads the app on iOS Device 2 and create some files etc. These files are different from those created on iOS Device 1
User then enables iCloud on iOS Device 1. This setting is propagated to iOS Device 2 using KV store of iCloud. Also the files in iOS Device 1 sandbox are moved to iCloud
Scenario 1:
User starts the app on iOS Device 2. I know that now iCloud is enabled and I prompt the user that it was enabled on some other device and I am moving your local files to iCloud. I think there is no problem here.
Scenario 2:
When the notification arrived (that iCloud is enabled on device 1) user was using the app on iOS Device 2 and had few modal views on the screen. I am not sure how to inform the user about the change and perform the operation i.e move device 2's sandbox files to iCloud.
Should all the viewcontrollers of the app have the capability to be interrupted and handle this event ?
Looking for some suggestions and guidance here on the user experience and right thing to do.
Save the a device-specific setting in NSUserDefaults and don't upload files automatically — it seems a little wrong to automatically upload things because a setting changed on another device. If you force the user to navigate to an "Enable iCloud Storage" view controller, you have much more control over what other VCs are visible and are less likely to run into surprises.
It could also be worthwhile making it a per-file setting (e.g. perhaps files they don't want in iCloud for security/space reasons).
Alternatively, a UIAlertView should work from anywhere in your app, but you'll have to make sure that files can be shifted to iCloud seamlessly while they're being viewed (and edited?) in a view controller.

Resources