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

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.

Related

Detect first time app download on iOS

I already have a application on App Store and business team needs to detect the users who's downloading and using the app for the very first time.
Challenge is there's no login for the app and customers can purchase tickets. We need to give a promotion only for the customers who downloaded after some future specific date. (ex : customers who will download for first time after 1st January 2018)
Even if the customer is deleting the app and then re install from apple store, it should not be eligible for the offer.
we can do some code fix and update. But that code will not be affected until they update and launch.
Note: It should be first time download only (i.e. they have never had the iOS app on their phone)
As far as my knowledge, There is no way for us to know whether a user has reinstalled user or not until unless we do have our own custom logic like sending emailId or storing in Keychain.
In your case, you have not done any of these things for the app which is already live in the app store. you can not track the reinstalled users. Please find the below segregation of users.
1. Reinstalled Users: right now not possible to track these users.
2. Installed Users (v1.0) & New Users.(V1.1)
check this solution How to determine the date an app is installed or used for the first time? to get the timestamp of the document file.
a. If it is less then new app release, then it should be an older version.
b. If it is equal or greater than the new app release timestamp, then it is the new version.
write the keychain logic in the new version so that from now onwards you can use keychain to identify the users.
Use CFUUID to create UUID, then save it in the keychain. So whenever the app launches, if no UUID is found in keychain, it can be said that app is installed for the first time. If UUID is found in keychain, it can be said that app has been installed previously. Have a look at below links:
iOS UDID replacement
UDID equivalent
iOS unique user identifier
In our case, we were keeping some local sqlite database in the documents folder. So if the file doesn't exist at the time of launch we can assume its a fresh launch. Otherwise its an update.

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.

How to reinstall an app without losing NSUserDefaults?

I have an iOS game that saves game progress using NSUserDefaults. After the last update a user had a problem, the app was not working anymore on this device. The app doesn't have any problem, but for some reason an error occurred while downloading the app, not quite sure what happened.
The point is, the app must be deleted and reinstalled. Can this be done without erasing NSUserDefaults?
I tried syncing with iTunes here after deleting the app, even installing it again through iTunes but I was unable to restore the previous saved game on my test devices.
I guess the only way to reinstall the app is through an app update. When it comes out he will update and will not lose any data. Is this correct? Or is there any other way to do this?
I'm working to implement cloud syncing on the next update, so this problem should not be an issue again :). But right now, is there anything and I do to this user?
Cloud sync would be the solution. If you using your iPhone only once the app is deleted every thing related to it is gone with no easy way to retrieve it.
Or just store data that needs to be persistent in the keychain.
Restoring the device from an iTunes Backupd probably reinstalls the app and also keeps the NSUserDefaults, assuming they are included in the backup.
However, this needs to be done by the user ...
Some syncing option is the better solution on the long way.

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

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.

Resources