iOS 目录的使用

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.
  • 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/目录应该是最为常用的目录!

时间: 2024-08-08 21:52:20

iOS 目录的使用的相关文章

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

转自:http://blog.sina.com.cn/s/blog_5fb39f910101di92.html IOS中获取各种文件的目录路径的方法 iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory()), 手动保存的文件在documents文件里 Nsuserdefaults保存的文件在tmp文件夹里 1.Documents 目录:您应该将所有

IOS管理文件和目录

1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path contents:(NSData *)data attributes:attr //向一个文件写入数据 -(BOOL)removeItemAtPath:path error:err //删除一个文件 -(BOOL)moveItemAtPath:from toPath:to error:err //重命名或者

IOS管理文件和目录NSFileManager

1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path contents:(NSData *)data attributes:attr //向一个文件写入数据 -(BOOL)removeItemAtPath:path error:err //删除一个文件 -(BOOL)moveItemAtPath:from toPath:to error:err //重命名或者

IOS开发-phonegap上的数据库

phonegap提供的本地数据库功能不可用,最终请教高手后使用SQLitePlugin插件来实现.网上很多都是介绍IOS插件如何编程,少有介绍如何使用插件: 一.插件安装: 1.下载,解压,复制以下文件: Cordova-SQLitePlugin-master\src\ios目录下的SQLitePlugin.h和SQLitePlugin.m,复制到phonggap项目的plugin目录下. Cordova-SQLitePlugin-master\www目录下的SQLitePlugin.js,复制

《iOS应用逆向工程》学习笔记(二)iOS系统目录结构(部分)

首先下载个iFile,可以用来直观地查看iOS系统的目录结构. 下面记录一些关键的iOS目录结构: /var:"variable"的简写,存放一些经常更改的文件,例如日志.用户数据.临时文件等.其中/var/mobile/Applications下存放了所有App Store App. /Applications:存放所有的系统App和来自Cydia的App,不包括App Store App.越狱的过程把/Applications变成了一个符号链接,实际指向/var/stash/App

iOS开发之集成ijkplayer视频直播

ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijkplayer, 即便以前从没有接触过, 按着下面做也可以集成成功! 编辑:Bison 投稿: jianshu_wl 一. 下载ijkplayer ijkplayer下载地址 下载完成后解压, 解压后文件夹内部目录如下图: 二. 编译 ijkplayer 说是编译 ijkplayer, 其实是编译 f

Hybrid App Development: 二、关于造轮子以及在Xcode iOS应用开发中加入Cordova

转载请注明出处:http://www.cnblogs.com/xdxer/p/4111552.html [ctrl+左键点击图片可以查看原图] 在上一篇关于Hybrid App Development的文章中,我讨论了一下在iOS下UIWebView的使用方法.但是光使用一个UIWebView所提供的功能还是完全不能满足我们的需求.   关于造轮子的思考: 在UIKit中的UIWebView虽然已经提供了很多功能了,比如JavaScript和Objc之间的通信.但是考虑到一个问题,如果在Hybr

Cordova for iOS[ PhoneGap]

安装这个费了点劲,和早前的PhoneGap有些不同. Cordova支持如下移动操作系统:iOS, Android,ubuntu phone os, Blackberry, Windows Phone, Palm WebOS, Bada 和 Symbian. Cordova是从PhoneGap中抽出的核心代码,贡献给Apache的项目,是驱动PhoneGap的核心引擎. 下载去apache即可. 安装说明: 1.下载node.js 2.安装node.js不说了,执行即可(npm随之安装) 3.终

IOS 之二 Xcode

关于Xcode集成开发环境安装使用与建立项目流程: 1.Xcode介绍及安装 Xcode:是苹果公司推出集成开发环境 语言:C/C++,objectc c,swift OSX,可用于IOS平台,ipad,iphone,苹果电脑 2.Xcode 创建IOS Single View项目 ①点击Create a new Xcode project(创建一个Xcode项目,选择IOS目录下Application), ②选择Single view Application,->next,填写项目名, 语言选