Какой самый безопасный каталог в iOS, который можно использовать для загрузки изображений/pdf-файлов?

Я использовал NSCachesDirectory в своем приложении для iPad для хранения изображений и PDF-файлов. Теперь мой клиент жалуется на то, что он не может видеть загруженный контент после нескольких часов загрузки. iPad имеет iOS 11.2.1.

Сначала я подумал, что может возникнуть ситуация с нехваткой памяти, и поэтому система iOS удаляет эти файлы, поскольку эти файлы хранятся в NSCachesDirectory. Но, на удивление, в iPad достаточно места, т.е. 4 ГБ свободного места, а загруженный контент имеет размер не более 500 МБ.

Итак, у меня есть несколько вопросов, связанных с этим:

(1) Несмотря на то, что на iPad достаточно места, почему система удаляет мои файлы?

(2) Может ли быть другая причина, по которой файлы удаляются из NSCachesDirectory?

(3) Если система iOS удаляет эти файлы, какое самое безопасное место в памяти приложения для загрузки этих файлов? Я обнаружил, что NSCachesDirectory — это сбрасываемая память, так что это не самое безопасное место.

(4) Будет ли NSDocumentDirectory лучшим вариантом для моего случая? или может быть другой вариант, предоставленный Apple?

Вот список каталогов приложений:

typedef NS_ENUM(NSUInteger, NSSearchPathDirectory) {
    NSApplicationDirectory = 1,             // supported applications (Applications)
    NSDemoApplicationDirectory,             // unsupported applications, demonstration versions (Demos)
    NSDeveloperApplicationDirectory,        // developer applications (Developer/Applications). DEPRECATED - there is no one single Developer directory.
    NSAdminApplicationDirectory,            // system and network administration applications (Administration)
    NSLibraryDirectory,                     // various documentation, support, and configuration files, resources (Library)
    NSDeveloperDirectory,                   // developer resources (Developer) DEPRECATED - there is no one single Developer directory.
    NSUserDirectory,                        // user home directories (Users)
    NSDocumentationDirectory,               // documentation (Documentation)
    NSDocumentDirectory,                    // documents (Documents)
    NSCoreServiceDirectory,                 // location of CoreServices directory (System/Library/CoreServices)
    NSAutosavedInformationDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 11,   // location of autosaved documents (Documents/Autosaved)
    NSDesktopDirectory = 12,                // location of user's desktop
    NSCachesDirectory = 13,                 // location of discardable cache files (Library/Caches)
    NSApplicationSupportDirectory = 14,     // location of application support files (plug-ins, etc) (Library/Application Support)
    NSDownloadsDirectory API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 15,              // location of the user's "Downloads" directory
    NSInputMethodsDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 16,           // input methods (Library/Input Methods)
    NSMoviesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 17,                 // location of user's Movies directory (~/Movies)
    NSMusicDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 18,                  // location of user's Music directory (~/Music)
    NSPicturesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 19,               // location of user's Pictures directory (~/Pictures)
    NSPrinterDescriptionDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 20,     // location of system's PPDs directory (Library/Printers/PPDs)
    NSSharedPublicDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 21,           // location of user's Public sharing directory (~/Public)
    NSPreferencePanesDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 22,        // location of the PreferencePanes directory for use with System Preferences (Library/PreferencePanes)
    NSApplicationScriptsDirectory NS_ENUM_AVAILABLE(10_8, NA) = 23,      // location of the user scripts folder for the calling application (~/Library/Application Scripts/code-signing-id)
    NSItemReplacementDirectory API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)) = 99,      // For use with NSFileManager's URLForDirectory:inDomain:appropriateForURL:create:error:
    NSAllApplicationsDirectory = 100,       // all directories where applications can occur
    NSAllLibrariesDirectory = 101,          // all directories where resources can occur
    NSTrashDirectory API_AVAILABLE(macos(10.8), ios(11.0)) API_UNAVAILABLE(watchos, tvos) = 102             // location of Trash directory

};

person NSPratik    schedule 15.12.2017    source источник
comment
Кэши могут быть удалены системой в любое время, поэтому не сохраняйте изображения там, NSDocumentDirectory — это место, где вы можете сохранять изображения, и они будут удалены только тогда, когда пользователь удалит приложение со своего телефона. p.s. с iOS 11 пользователь может удалить приложение, но сохранить документы и данные.   -  person Arthur Sahakyan    schedule 15.12.2017
comment
Спасибо... Любая идея по вопросу нет. 1?   -  person NSPratik    schedule 15.12.2017
comment
Вы говорите о NSCache или NSCacheDirectory ?   -  person NSPratik    schedule 16.12.2017
comment
Хранить в папке Документы. не в кеше. кеш для кеша, а не для пользовательских данных. кеш означает загруженные эскизы или другие файлы, которые можно удалить (при необходимости приложение будет загружаться снова). А еще лучше, после сохранения в папке документов, а затем синхронизировать с iCloud.   -  person GeneCode    schedule 18.12.2017
comment
мой ответ верен для обоих, NSCache и NSCacheDirectory могут быть удалены системой.   -  person Arthur Sahakyan    schedule 18.12.2017