Is data stored in NSUserDefaults persists through application updates and on application reinstallation (remove-install)? - ios

It's important to my app, becuase I want to store app UDID there, and Apple recommends to create app specific UDID starting from iOS 5.0.

User defaults are persisted through updates but are not persisted through deleting and re-installing the app. At present, the keychain is persisted through deleting and re-installing the app, but it's not documented to be one way or the other, so relying on this behavior may be risky.
You could also write the value to the iCloud key/value store. That will be persisted across all installations of the app for that user and is kind of what it was designed for.

Generally no. In some cases however, especially if a user is installing a cracked version of your app, then yes, some user defaults may stay, due to the way that many users install cracked applications, which creates backups of the documents / library folders on uninstall.

Related

iOS app crashed even after reinstalled, but not for the new users

Some of my old app users are experiencing app crashes for a certain step after I updated the app. Even when they tried to delete the app and reinstalled it, it's still crashing. However, the app doesn't crash for new users.
How does that happen? When a user completely deletes the app and reinstalls it from the AppStore, the user should be like a new user, right? How come the new users don't crash while the users who re-install the app keep crashing?
Is there something remaining in the device even after the user deletes the app?
If you use keychain functionality that may persist across uninstalls and reinstalls. That, in theory, is the only data that should persist with that behavior.
Without more code or details it's hard to know what the problem might be, but to your question "Is there something remained in the device...": yes, keychain information.
One thing that does remain in the device after uninstalling an app is privacy settings (Relevant SO post).
Perhaps you're trying to access something incorrectly with your update?
Are you using any database in your project?
If yes we need to take care of version migration.

Realm Swift: Is it possible to keep database after the apps is uninstalled?

Using realm swift, is it possible to keep and maintain the realm database file of the apps in device memory even after the apps is uninstalled from the device?
Thank you very much for any help.
Sadly not. This is a limitation of iOS more than a limitation of Realm. When an iOS app is uninstalled from a device, all of the files associated with it are deleted (including any Realm files).
If you want file data to persist even after the app is deleted, you'll need to look at a cloud hosting solution to hang onto a copy of those files. In this case, the easiest one would most likely be CloudKit.
Applications all files are leftover when deleting an app. iOS apps are Sandboxed. This means that each App has its own space in disk, with its own directories, which act as the home for the app and its data.
Deleting an app from the iPhone deletes this sandbox, deleting all data associated with the app.

Different UUID in swift 2.2

Before Swift 2.2 the UUID value was the same every time I opened the app, now changes at every opening
I use this code:
UIDevice.currentDevice().identifierForVendor!.UUIDString
How can I do now to identify the user?
Every time you delete the app, the UUID may change.
If you just close and open the app, it's should be the same.
But if you delete the app (or install it again via xcode), it might change.
There are a couple of answers that explain why the UUID is resetting. There's one that offers a potential work around, but I'd consider it far from ideal. But I want to highlight something important about the way UUID's work that serves as a great workaround that has absolutely zero impact on the production OR debug version of your code base or compiled binary.
The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.
All you have to do to prevent this value from changing while developing App-A is to simply install App-B from the same vendor (yourself) and keep it installed during the life time of App-A's development. This is literally as simple as starting a blank new iOS project and install the blank slate to your test device (using the same developer account & such), and then never uninstall it again during development.
App-B keeps a constant UUID for the vendor (yourself) so no matter how many times you delete and reinstall App-A, it will always keep the same UUID.
This actually seems to be a bug IMO. Everytime I run my app in the simulator it generates a new Vendor ID. You can probably get round it by storing the ID into NSUserDefaults on the first bootup then retrieving / comparing the value from NSUserDefaults instead of getting it from identifierForVendor. This will save a static vendor id in defaults but in theory the vendor id will still be changing every boot up.
Kind Regards,
Krivvenz.
Update: I can confirm I have installed multiple apps on the same simulator too but the vendor ID is still changing on every boot.
Update 2: - I have logged this as a bug with Apple - 26195931.
The value of this property is the same for apps that come from the
same vendor running on the same device. A different value is returned
for apps on the same device that come from different vendors, and for
apps on different devices regardless of vendor.
The value in this property remains the same while the app (or another
app from the same vendor) is installed on the iOS device. The value
changes when the user deletes all of that vendor’s apps from the
device and subsequently reinstalls one or more of them. The value can
also change when installing test builds using Xcode or when installing
an app on a device using ad-hoc distribution. Therefore, if your app
stores the value of this property anywhere, you should gracefully
handle situations where the identifier changes.
Refer this link for more info.

IOS: Data persistence between versions of the app

I cannot find any information on topic: what is happening when I release new version of iOS application on iTunes? Is older version on device completely replaced? Or there is a persistence of Documents folder?
Is it possible to make update to be like a "clean" installation?
When you release an update to your iOS app and the user installs it, the system does not wipe out any data from within the app.
This means that data in a given user's Documents directory, NSUserDefaults, as well as the keychain will persist between app updates.
A couple of important notes, however:
The Caches directory of an app is never reliably persisted, so if you want to make sure data stays safe, don't put it in this directory
Items in the keychain seem to persist even if you completely erase the app and re-install it. I've noticed this in the past, so it may be a good thing to keep in mind
In short, if you want data cleaned out of your app on each update (not sure why you would), you'll have to do so manually.
Your Documents folder will not be cleaned.
If you want to clear it, make sure to do it programmatically in your new release.
The Documents folder is deleted only when the user deletes the app.

iOS: why some app can restore the account info when reinstalled

Some apps, If you have ever used it on your iPhone once and then uninstalled it, the next time you install the app, the app can still retrieve your info that you filled out before you uninstalled it last time.
How does the app do this?
It's because they save account information on the keychain.
Data stored in the keychain persist even if you uninstall the application, they are only removed if you perform a full restore of the device, or you remove by yourself.
This is a complete different behavior respect to NSUserDefault that is removed within the application deletion.
Data in keychain can also be shared between applications (if you implement it in the correct way) that use a similar bundle identifiers.

Resources