Deleting App should not delete Document Directory - ios

Is there any way not to Delete document Directory If iOS App is get unnistaled or any alternate way
or
Is there any way we can save data on different place so that after deleting app we can use it?

No there is no way to prevent system from deleting the documents folder once you uninstall the app.
And if an iCloud is enabled in the device, it will backup the contents of the Documents directory. iCloud way is the most efficient as it handles documents folder content automatically, it puts data back from the backup after reinstalling, so you can reuse it.
Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.
More: https://developer.apple.com/icloud/documentation/data-storage/index.html
A user may also have backed up these data with iTunes.
Read more about file system and logic:
https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

Related

Can I create a Documents directory in Xcode, and put files in it for my iOS app through the UI. If so, how?

I need to read/write a tiny amount of info for data persistence in an iOS app. I am using plists and understand that I can read, but not write to the bundle. If I create the plist files initially at development time, how can I place the plists in the "Documents" area of my app so that they are later writable?
Short answer: No.
As you say, an iOS app's bundle is not writable, but it is readable.
Further, an app's documents directory doesn't exist until the app is run (on the user's target device) for the first time. Thus, you can't build your app's documents directory at compile-time, nor can you submit an app to the app store with a prepopulated Documents directory. (It would be nice if Apple gave us the ability to provide a "seed" documents directory that got moved to the documents directory at first launch, but they do not provide that facility -- at least not that I'm aware of.)
What you can do is to create a sub-directory of your bundle that contains a set of files that you want to place in the app's documents directory.
On launch, check a "hasBeenInstalled" flag in UserDefaults. If it's true, do nothing. if it's false, use the file manager to copy files from your app's bundle into the app's documents directory, then write hasBeenInstalled=true to UserDefaults.

Are app files unique to installations

I'm planning on having a generated file be stored in the App/Documents file for my app. I want this file to be unique across installations so that if a user has an iPad and an iPhone they will have two different versions of the file.
I've been reading the specification(https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html) and am particularly concerned about this line.
Use this directory to store critical user documents and app data files. Critical data is any data that cannot be recreated by your app, such as user-generated content.
The contents of this directory can be made available to the user through file sharing. The contents of this directory are backed up by iTunes.
My question is will the files be backed up to the users account in the cloud?
yes it is. The Documents Directory is a key location in an app. which means that if you put anything in the documents, it will back up to itunes(if the user wants to). so even if you generated a unique file across installations, it will re-download the EXACT file to a new system if they downloaded it previously. so unique files in the DOCUMENTS will not be possible (unless a person uses a diffrent apple account on every one of his devices. which is not likely.)

Is Core Data sqlite database in the documents directory automatically backed up by iCloud?

I'm working on a project that requires the Core Data database to be backed up somehow so that the data won't be lost if user deletes and re-downloads the app.
In the iOS storage guideline it states:
Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.
I wonder whether it means that if I put my Core Data sqlite database in the /Documents directory, it will get backed up automatically by iCloud?
If not, is there any simple solution for backing up the Core Data database? I just need the database to be recoverable after app being removed and re-installed. Syncing between devices isn't my aim here.
Yes, putting your database in the Documents directory will do exactly what you want: allow back up to iCloud without syncing to iCloud.
Syncing requires moving to the ubiquity container, but thats not what you want.
More information can be found in the Apple Technical Note which explains how to exclude a file from backup. Of course, for the backup to work, the user has to have set up their device to back up to iCloud.
Edit: Here is another helpful link: Apple's App Backup Best Practices section of the iOS App Programming Guide.

retain program data in iOS app while updating and sync to iCloud

When a new upgrade is released and installed on iOS, which folders / files are left untouched by the upgrade process? There are several folders; Library, Caches, Preferences, Documents.
Normally Application Support Directory is not created by default. What happen to AS folder during upgrade?
I learn that all data in Documents folder will copy to iTunes or iCloud by default. Is that true?
If I create my own CoreData db to persist, where should I keep?
Your best bet is to read the first half (which pertained to iOS) of this document from Apple:
In my experience, I put Core Data db in Documents folder if the iTunes File Sharing feature was not enabled on your app. Otherwise create a folder in the Library folder called Application Support or anything name, etc. With iTunes File Sharing enabled, user can accidentally delete any files in the Documents folder.
During the upgrade, the contents of Library and Documents folder are retained.

Is iOS 5 iCloud Backup save webkit data for app using the storage of a UIWebView?

I have a phonegap iOS app using the sqlite DB of Webkit (through UIWebView), and I wonder if the sqlite data will be saved with iCloud Backup (iOS5). The sqlite data are stored in Library/WebKit folder. In the apple doc, they say:
The placement of files in your application’s home directory determines what gets backed up and what does not. Anything that would be backed up to a user’s computer is also backed up wirelessly to iCloud. Thus, everything in the Documents directory and most (but not all) of your application’s Library directory.
But it can say exactly which folder in the library directory are not saved. And I don't know how to access iCloud to check if the directory is saved
Library/WebKit is included in the backup. With the exception of Library/Caches, everything in the Library directory is backed up.
The data included in an iCloud backup for your app is identical to that included in an iTunes backup, so you can examine the contents by backing up to iTunes and using a tool like iPhone Backup Extractor to see what's included.

Resources