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

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.

Related

Is it possible to retrieve deleted iOS simulator app data?

I've been working on an iOS app and making lots of progress on tweaking a sqlite DB. Using FMDB to interact with the DB, the copy I was working from was the one copied into the simulator app's bundle, not the version that sits in Xcode. I accidentally deleted the app from the simulator, and with it several days of progress on this DB I've been working on. Is there anyway to get that data back? Where do deleted simulator apps go to die?
It won't be possible to get anything of deleted application until and unless you are storing it to permanent storage i.e Keychain.
So, It's not possible to get the DB file for your previous installed application.

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.

Is it possible to retain data of the older version if a new version of app is deployed on device?

I am new to iOS development so my question may be n00bish.I am working on an app for iPad which downloads PDFs and stores on the device(iPad) in the Documents directory so the user can still read them if he isn't connected to WiFi. My question is:if a newer version of the app is available and the user installs it, will it delete all the data(documents,in this case) from the device? If yes,how do I prevent the old data from being deleted? I am using CoreData in this app(if this helps)
When a user installs an updated version of any app, the app's sandbox is kept intact. Only the app and its resource bundle are replaced. So basically, anything you have stored in Documents or Library will be kept intact after the update process. There is no guarantee that files in Library/Caches or tmp will be kept but those should only have transient files anyway.

Questions concerning iCloud + core data

I have an app on the app store, that uses coredata as storage. I wan't to update the app with iCloud synchronization as new feature. Following apple`s sample code, I managed to have my core data storage synchronize between devices.
However, I'm experiencing problems when either iCloud synchronization is turned off/on in the app on only one of the devices, or when the app is deleted from the device and the reinstalled. In both cases, data is not synchronized back to the device, although it is available just fine on a second device (which was not disabled/reinstalled).
I also found that all storage is effectively erased completely, when I delete the app from all devices, and then reinstall. Althrough I get a couple of merge notifications in the console (even some without errors), I can't see no data in the local storage of the device.
Browsing the mobile documents folders on my mac still reveals lots of transaction logs in the icloud storage of my app.
Even deleting the app from all devices and starting from scratch wont sort things out. I will end up in a situation where data is either only synced to one device, or not synced at all.
I wonder if there is anything I can do about this inconsistent state that is created when only one device is temporarily iCloud disabled, or the app is deleted from ONE device?
As for my code, its an 1:1 copy of the recipces example from apple.
Daniel Pasco talked about using Core Data and iCloud together at NSConference 2012. Some notes from that blog post:
launching with -com.apple.coredata.ubiquity.logLevel 3 to get a spamfest in the message log saying what Core Data and iCloud are doing.
The conclusion from this talk appears to be that using Core Data and iCloud are really not ready for each other at this stage.
He posted an updated Core Data Recipes project on Github which may or may not fix your problem.
Apple makes it seem easy, but there are a number of nuances with regard to correctly seeding iCloud with data, and what happens afterwards when iCloud support is toggled on and off on different devices.
I implemented a sample project that demonstrates a straightforward way to add iCloud support to Library-style CoreData apps. It's called iCloudStoreManager and it's available on github.
I'm still testing it before I add iCloud support to one of my own production apps. It's working, but I see unexpected errors and delays when an iPad 3 is in the mix. It works, but with long delays.
I've also tested with iPhone 4, iPhone 4S, and the original iPad, and any mix of those devices works well in my experience.

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