• About Files and Directories(iOS文件与目录)


    参考:

    Every App Is an Island

    An iOS app’s interactions with the file system are limited mostly to the directories inside the app’s sandbox. app与文件系统交互被限制在app的沙盒目录里。

    During installation of a new app, the installer creates a number of containers for the app. Each container has a specific role.新app安装,创建一些containers,每个container有特殊用途。

    The bundle container holds the app’s bundle, whereas the data container holds data for both the application and the user. bundle container包含app的bundle,数据container包含应用和拥护的数据。

    The data container is further divided into a number of directories that the app can use to sort and organize its data.

    数据container被进一步分成多个目录,这些目录可以供app进行排序组织数据。

    The app may also request access to additional containers—for example, the iCloud container—at runtime.

    app有可能在运行时,请求访问其他container,比如icloud container.

    an app is generally prohibited from accessing or creating files outside its containers. app通常禁止在container外获取或者创建文件。

    One exception to this rule occurs when an app uses public system interfaces to access things such as the user’s contacts or music.

    一个例外是app使用共有系统接口来访问比如用户联系人信息或者音乐。

    In those cases, the system frameworks handle any file-related operations needed to read from or modify the appropriate data stores.

    这种情况,系统framework处理任何所需的文件相关操作(如:读取或修改合适的数据store)

     

    子目录:

    Directory

    Description

    AppName.app

    只读的

    This is the app’s bundle. This directory contains the app and all of its resources.

    You cannot write to this directory. To prevent tampering, the bundle directory is signed at installation time. Writing to this directory changes the signature and prevents your app from launching. You can, however, gain read-only access to any resources stored in the apps bundle. For more information, see the Resource Programming Guide

    The contents of this directory are not backed up by iTunes. However, iTunes does perform an initial sync of any apps purchased from the App Store.

    Documents/

    Use this directory to store user-generated content. 存储用户生成的内容  The contents of this directory can be made available to the user through file sharing;  这个目录的内容可以通过文件共享对用户可见   therefore, his directory should only contain files that you may wish to expose to the user.

    The contents of this directory are backed up by iTunes.

    Documents/Inbox

    Use this directory to access files that your app was asked to open by outside entities.  如果app被外界entitle要求去打开一些文件,去这个目录来访问文件。

     

    Specifically, the Mail program places email attachments associated with your app in this directory. 邮件程序放置把邮件附件放在这个目录里。

    Document interaction controllers may also place files in it.

    Your app can read and delete files in this directory but cannot create new files or write to existing files. 这个目录可读,可删除,不能新建文件,修改已有文件。

    If the user tries to edit a file in this directory, your app must silently move it out of the directory before making any changes. 在对目录里的文件进行编辑前,必须先把它从目录移除。

    The contents of this directory are backed up by iTunes.

    Library/

    This is the top-level directory for any files that are not user data files. 非用户文件的顶级目录

    You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories.

    Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.

    The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes.

    For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.

    tmp/

    Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.

    The contents of this directory are not backed up by iTunes.

    An iOS app may create additional directories in the Documents, Library, and tmp directories. You might do this to better organize the files in those locations.

    For information about how to get references to the preceding directories from your iOS app, see Locating Items in the Standard Directories. For tips on where to put files, see Where You Should Put Your App’s Files.

     

    Where You Should Put Your App’s Files(在哪放app的文件)

    Put user data in Documents/. User data generally includes any files you might want to expose to the user—anything you might want the user to create, import, delete or edit. For a drawing app, user data includes any graphic files the user might create. For a text editor, it includes the text files. Video and audio apps may even include files that the user has downloaded to watch or listen to later.

     

    Put app-created support files in the Library/Application support/ directory. In general, this directory includes files that the app uses to run but that should remain hidden from the user. This directory can also include data files, configuration files, templates and modified versions of resources loaded from the app bundle.

     

    Remember that files in Documents/ and Application Support/ are backed up by default. You can exclude files from the backup by calling -[NSURL setResourceValue:forKey:error:] using the NSURLIsExcludedFromBackupKey key. Any file that can be re-created or downloaded must be excluded from the backup. This is particularly important for large media files. If your application downloads video or audio files, make sure they are not included in the backup.

     

    Put temporary data in the tmp/ directory. Temporary data comprises any data that you do not need to persist for an extended period of time. Remember to delete those files when you are done with them so that they do not continue to consume space on the user’s device. The system will periodically purge these files when your app is not running; therefore, you cannot rely on these files persisting after your app terminates.

     

    Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.

     

     

     

    Files, Concurrency, and Thread Safety 文件并发线程安全

    most of the file-related interfaces in iOS and OS X are designed with concurrency in mind

     

     

  • 相关阅读:
    Android使用Eclipse遇到"java.lang.ClassNotFoundException"
    Android WebView中显示一张或多张图片
    Eclipse中集成Perforce插件
    好文章收集
    设计与原型工具
    digital ocean 内存不足时增加swap文件的方法
    Stop Bitbucket prompting for password in git
    npm WARN unmet dependency问题的解决方法
    phpstorm 的.idea 目录加入.gitignore无效的解决方法
    websocket php lib---Ratchet
  • 原文地址:https://www.cnblogs.com/cocoabanana/p/5549576.html
Copyright © 2020-2023  润新知