一? An iOS app operating within its own sandbox directory
在自己的沙盒目錄下運行的iOS應(yīng)用程序
An app is generally prohibited from accessing or creating files outside its container directories. One exception to this rule is when an app uses public system interfaces to access things such as the user’s contacts or music. In those cases, the system frameworks use helper apps to handle any file-related operations needed to read from or modify the appropriate data stores.
應(yīng)用程序通常不允許在它的容器目錄之外訪問或創(chuàng)建文件。一個例外是當(dāng)應(yīng)用程序使用公共系統(tǒng)接口去訪問例如用戶的聯(lián)系人或音樂。在這些場景,系統(tǒng)框架使用開發(fā)者幫助文檔去處理需要從適當(dāng)?shù)臄?shù)據(jù)存儲讀取或修改的任何文件相關(guān)的操作绪穆。
二? 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:
為了防止在iOS設(shè)備同步和備份使用很長的時間钠怯,你的文件存儲位置是可以被選擇的。存儲大文件的應(yīng)用程序會減慢備份到iTunes或iCloud的過程节值,這些應(yīng)用也會消耗大量用戶可用空間锯梁。這些都會促使用戶刪除應(yīng)用或者不再備份應(yīng)用的數(shù)據(jù)到iCloud适贸。基于此涝桅,你應(yīng)該按照如下指南進行存儲應(yīng)用數(shù)據(jù)。
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.
將用戶數(shù)據(jù)存放在Documents/. 路徑烙样。用戶數(shù)據(jù)一般包括你可能想暴露給用戶的任何文件冯遂,你可能想讓用戶創(chuàng)建、引入谒获、刪除或編輯的任何數(shù)據(jù)蛤肌。對于一個繪制應(yīng)用程序,用戶數(shù)據(jù)包含用戶可能創(chuàng)建的任何圖表文件批狱。對于一個文本編輯器裸准,它包含一些文本文件。視頻和音頻類應(yīng)用可能甚至包含用戶已經(jīng)下載后要觀看或收聽的文件赔硫。
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.
將應(yīng)用創(chuàng)建的支持文件放在路徑Library/Application support/ directory炒俱,一般而言,這個目錄包含應(yīng)用運行需要的但是對用戶而言應(yīng)該要隱藏的文件爪膊。該目錄還可以包含從app bundle中加載的數(shù)據(jù)文件权悟、配置文件、模板和修改版本的資源
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.
記得Documents/ and Application Support/目錄下的文件默認(rèn)會備份推盛。通過使用NSURLIsExcludedFromBackupKey鍵調(diào)用-[NSURL setResourceValue:forKey:error:]可以從備份中排除文件峦阁。任何可以重新創(chuàng)建或下載的文件都必須排除在備份之外。這對于大型媒體文件來說尤其重要耘成。如果你的應(yīng)用下載視頻或音頻文件榔昔,確認(rèn)他們不是包含在備份中驹闰。
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.
將臨時文件存儲在tmp/目錄。臨時數(shù)據(jù)包含你不需要長期使用的任何數(shù)據(jù)撒会。記得去刪除這些文件當(dāng)你已經(jīng)使用完了嘹朗,因此他們不會繼續(xù)占用用戶設(shè)備的空間。當(dāng)應(yīng)用不再運行時系統(tǒng)將會定時清除這些文件茧彤;因此當(dāng)應(yīng)用終止時你不能依賴這些文件持久化
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.
將數(shù)據(jù)緩存文件存儲在Library/Caches/ 目錄骡显。緩存數(shù)據(jù)可以應(yīng)用于任何需要比臨時文件持久化的數(shù)據(jù),但是沒有支持文件更久曾掂。一般而言惫谤,應(yīng)用不會要求緩存數(shù)據(jù)也能正確操作,但它可以使用緩存數(shù)據(jù)來提升性能珠洗。緩存數(shù)據(jù)的例子包含(但不限于)數(shù)據(jù)庫緩存文件和臨時的溜歪、可下載的內(nèi)容。系統(tǒng)會刪除Caches/目錄清空磁盤空間许蓖,因此當(dāng)需要這些文件的時候你的應(yīng)用必須可以重新創(chuàng)建或下載蝴猪。
三 總結(jié)
1、存儲內(nèi)容類型
/Documents一般會存儲用戶生成的內(nèi)容,此目錄應(yīng)該只包含您可能希望向用戶公開的文件
/Library/ 一般不會存儲用戶數(shù)據(jù)文件膊爪,此目錄包含不希望向用戶公開的任何文件
/tmp/? 一般會存儲在應(yīng)用程序啟動期間不需要持久保存的臨時文件自阱,此目錄會在應(yīng)用不再運行時被清空
2、文件備份情況
/Documents這個目錄的內(nèi)容由iTunes和iCloud備份
/Library/? ? ? ??這個目錄的內(nèi)容由iTunes和iCloud備份
/tmp/? ? ? ? ? ? 這個目錄的內(nèi)容沒有iTunes或iCloud備份
四 目錄說明
Table 1-1 lists some of the more important subdirectories inside the sandbox directory and describes their intended usage. This table also describes any additional access restrictions for each subdirectory and points out whether the directory’s contents are backed up by iTunes and iCloud.
表格1-1列出了一些在沙盒目錄更重要的子目錄并描述了它們的預(yù)期用途米酬。這個表格也描述了對于每個子目錄的任何額外訪問限制沛豌,同時指出了目錄內(nèi)容是否從iTunes和iCloud中備份的。
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 or iCloud. 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, this directory should only contain files that you may wish to expose to the user.The contents of this directory are backed up by iTunes and iCloud.
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 and iCloud.
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 and iCloud.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 or iCloud.
五? 文檔相關(guān)
文檔參考? https://developer.apple.com
如對讀書赃额、測試感興趣的小伙伴可關(guān)注如下WeChat:琦哥私房菜加派,小編會分享讀書筆記和測試技術(shù)文章,希望同大家一起進步跳芳。