Table 1-1  Commonly used directories of an iOS app 

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. 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 DocumentsLibrary, 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

To prevent the syncing and backup processes on iOS devices from taking a long time, be selective about where you place files. Apps that store large files can slow down the process of backing up to iTunes or iCloud. These apps can also consume a large amount of a user's available storage, which may encourage the user to delete the app or disable backup of that app's data to iCloud. With this in mind, you should store app data according to the following guidelines:

  • 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. 注意,这个backup信息是不能在程序中使用的,是ios系统自己用的backup,自己使用需要用icloud相关内容。

  • 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.

总的来说,可以再次下载的内容,最好无论大小,都放到Library/Caches/目录中,当文件被删除时要有逻辑进行重新下载!Library/Caches/目录应该是最为常用的目录!

iOS 目录的使用的更多相关文章

  1. iOS目录结构

    默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 Documents:苹果建议将程序中建立的或在程序中浏览到的文件 ...

  2. IOS的Application以及IOS目录的介绍

    1.UIApplication介绍 .UIApplication对象是应用程序的象征 .每一个应用都有自己的UIApplication对象,而且是单例的 .通过[UIApplication share ...

  3. Xamarin.ios 目录结构

    1.Resources: 文件夹存放应用程序所. 2.AppDelegate.cs: 主要的应用程序类别(class) ,并接听 系统事件及相对应的事件处理. 3.Entitlements.plist ...

  4. IOS管理文件和目录

    1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path cont ...

  5. iOS中获取各种文件的目录路径的方法

    我们的app在手机中存放的路径是:/var/mobile/Applications/4434-4453A-B453-4ADF535345ADAF344 后面的目录4434-4453A-B453-4AD ...

  6. IOS管理文件和目录NSFileManager

    1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path cont ...

  7. IOS中获取各个文件的目录路径的方法和NSFileManager类

    转自:http://blog.sina.com.cn/s/blog_5fb39f910101di92.html IOS中获取各种文件的目录路径的方法 iphone沙箱模型的有四个文件夹,分别是什么,永 ...

  8. Xamarin体验:使用C#开发iOS/Android应用

    Xamarin是Mono创始人Miguel de Icaza创建的公司,旨在让开发者可以用C#编写iOS, Android, Mac应用程序,也就是跨平台移动开发.   简介 Xamarin是基于Mo ...

  9. ios native工程集成react-native的demo

    react-native看到了给现有工程添加react-native环境的时候碰到一个问题: 如何往工程中添加 package.json文件,以及node_modules是怎么来的? 我开始的时候以为 ...

随机推荐

  1. Java面试笔记

    1.&和&& if(str != null& !str.equals("")){ System.out.println("ok" ...

  2. StringUtils

    StringUtils.hasText(字符串) 如果字符串里面的值为null, "", "   ",那么返回值为false:否则为true

  3. Android Studio-设置鼠标悬停显示方法声明

  4. C#多线程学习(一) 多线程的相关概念(转)

    什么是进程?当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.而一个进程又是由多个线程所组成的. 什么是线程?线程是程序中的一个执行流,每个线程都有自己的专有寄 ...

  5. lishell学习之路:流程控制(case)

    流程控制case语句: 介绍:多分支case条件语句 1.case语句和if..elif..else语句一样都是多分支条件语句,不过和if多分支条件语句不同的是,case语句只能判断一种条件关系,而i ...

  6. C生成随机数,奇葩问题

    今天需要生成一个随机数,奇怪的问题发生了. #include <stdio.h> #include <stdlib.h> #include <time.h> #de ...

  7. php各种编码集详解和以及在什么情况下进行使用

    字符是各种文字和符号的总称,包括各国家文字.标点符号.图形符号.数字等. 字符集是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,常见字符集名称:ASCII字符集.GB2312字符集.B ...

  8. jQuery 学习之路(3):DOM操作

    一.在元素内部插入 .append(content[,content]) 在指定元素的内部末尾插入字符串,或在指定元素的内部末尾移入指定元素,如 $(".container").a ...

  9. solr6.1-----相关配置-详细介绍-启动-全文检索

    环境准备 jdk1.8.0_60  + apache-tomcat-8.5.4 + solr-6.1.0 进过测试.使用tomcat 7.x  不能正常启动solr .会报错,至于怎么原因,lz 暂时 ...

  10. CSS Reset样式重置

    为了让页面在各不同浏览器之间显示效果一致,CSS样式清除和重置是前端开发必需要做的事情,结合前车之鉴,整理了份CSS重置样式代码供参考. @charset "utf-8"; /* ...