Where to store personal important user data if the Documents directory is not an option?

My application uses iTunes file sharing, which provides the user with the entire contents of the Documents directory, which makes it vulnerable to accidental deletion or manipulation.

I read these documents for hours, but this is a mess, and I hope someone knows from experience. First, in one place they say that I should put these files in the Library directory.

In this technical Q and A, Apple says it persists. In my opinion, this means that I can safely place important user data, such as sqlite3 database files in this directory. When the user is updated to the new version, the contents inside this directory will be saved, it will be saved and will be available after the update:

Applications

can create their own directories in / Library / and those directories will be backed up and updated.

So / Library / is saved in backups and updates.

For me with poor English, this means: YES, the data will survive. It will not be lost when the user backs up. It will not be lost when updating by the user. I searched for the word "preserved" in several dictionaries, and I'm sure that means "he will survive."

But then there is this note in the iOS Application Programming Guide , which says something completely different! Here they talk about the library directory:

<Application_Home>/Library/ You should not use this directory for user data files. The contents of this directory (with the exception of the Caches subdirectory) are backed up by iTunes. Your application is generally responsible for adding and removing these files. It should also be able to re-create these files as needed because iTunes removes them during a full restoration of the device. 

"Should not be used for user data files." (???)

But at the same time, they acknowledge that it is supported by iTunes. OK. So why shouldn't I put user data files there?

/ Library / caches Use this directory to write any application support files that you want to launch the application or during application updates. (...) It should also be able to recreate these files as needed, as iTunes deletes them during a complete restoration of the device.

What?! I have to put these files in Library / Caches. But this directory is not supported by iTunes , as they said above. So this is only saving updates, but not for backup. And the data can be deleted at any time by the system.

Now this is completely confusing for me. From what I understand, I can choose between evil and the devil: the data in / Library / does not withstand updates, but is backed up by iTunes. Data in / Library / Caches is saved in updates, but is not supported by iTunes. They can be deleted by the system (as it is "Cache") at any time.

And, on the other hand, technical Q and A suggest putting this important user data in a user subfolder in / Library /, for example / Library / PrivateDocuments.

Unlike the iOS app programming guide, the technical questions Q and A state: the entire directory / library was always kept during updates and backups

So, indeed, one of the two documents MUST be erroneous. But which one? What is the truth? Please do not speculate! I am looking for answers based on experience, and I feel that there is no way to understand this other than the release of the appendix and prayer. Maybe someone wants to share their experiences, which really worked.

+6
source share
3 answers

I saw that Library / Preferences (where NSUserDefaults are stored) are stored at all stages of recovery, so I believe that most of the library is stored. However, cache directories are excluded.

In general, just use the API to retrieve the paths and believe that iTunes will save them if they are not intended to represent temporary folders. This means that you must use the subdirectory of your NSApplicationSupportDirectory named for your application:

 NSArray * urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; NSAssert([urls count], @"Can't get app support directory"); NSURL * url = [urls objectAtIndex:0]; url = [url URLByAppendingPathComponent:@"MyAppName"]; 

In practice, this will be "Library / Application Support / MyAppName" in your sandbox, but you should use the API in any case to ensure that this is preserved in the future.

(If you need iOS 3 or 2 support, use the NSSearchPathForDirectoriesInDomains() function instead of the -URLsForDirectory:inDomains: method.)

+3
source

Why don't you try the keychain? If your data is not too extensive, this can provide a quick way to store sensitive information.

Apple Documentation Form

+1
source

The contents inside the Library folder (other than the cache) is a backup of itunes.

What does the apple mean under "Do not use for user data files". (???) is that do not use this folder for the data that you want to view in the file sharing system via itunes.

So, if you want the user to access data through itunes, write to the / Document folder

If you want to hide data from a user entry in the / Library folder

+1
source

Source: https://habr.com/ru/post/888939/


All Articles