国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS沙盒簡單介紹

2019-11-14 18:28:57
字體:
來源:轉載
供稿:網友

先簡單介紹一下什么是沙盒:你可以簡單理解成為一個目錄,這個目錄的改動不會對操作系統造成任何損失。(這里也有一點點介紹

看看蘋果的沙盒目錄:

再附一張蘋果官方的圖

一個iOS app操作都是在自己的沙盒中進行的。

首先:

Deveices,里面是各種的模擬器設備。

然后隨便找一個模擬器設備。里面的data是里面的數據。然后Container里面Data中有一個application就是該設備的安裝軟件。

我們可以看到里面有好多個(就算我們Reset Content and Settings,也會有。因為里面有設備自帶的軟件,例如通訊錄,地圖等。)。

隨便打開一個就可以看到里面某個程序包括三個目錄:

Documents

Library:又包括Caches和PReferences

temp

其中的

Documents只有用戶生成的文件、其他的數據以及程序程序不能創建的文件,這里的數據通過iCloud自動備份。我們錄制的音頻和拍照的圖片都可以放到這里。

Library:可以重新下載或者重新生成的數據應該保存在Library的caches目錄中。這里用于盛放緩存。

tmp:是臨時使用的數據。iCloud不會自動備份這些文件,這些數據使用完后要隨時刪除,避免占用用戶設備空間。

- (NSString *)documentDirectory {    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    return [paths objectAtIndex:0];}

通過上面這個方法可以得到:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/34361283-8619-481D-B8CB-B25EB4B787E2/Documents

也就是Documents的路徑.

還可以得到通過下面的方法:

 NSString *s = NSHomeDirectory();

得到如下結果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/08A6D627-1363-48B4-8AF8-A1ED361DC9D6

故名思議,我們通過NSHomeDirectory得到了該安裝軟件的目錄。(里面就包括Documents/Library/temp)

蘋果官方介紹的是返回用戶的或者應用程序的家目錄,依賴于平臺。

 

再來看一下如何取得Caches目錄路徑的方法:

  NSString *s = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

返回結果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/DB647E93-5F05-4B7B-A8E9-F6F01DD2586B/Library/Caches

最后看一下如何獲取tmp目錄:

  NSString *s = NSTemporaryDirectory();

返回結果:

/Users/zhanggui/Library/Developer/CoreSimulator/Devices/B6134687-CC10-40DE-BD9D-A2E5AD2D5C03/data/Containers/Data/Application/C7CA833E-8D20-480B-AB91-234A8F17336D/tmp/

--------------------------------------------------------------------大概就這么多吧--------------------------------------------------------------------

NO ,NO ,NO看看蘋果官方的說明吧:

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

英語好的大神可以看一下。不好的飄過,,,,

更多請見:https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万全县| 东丽区| 庆云县| 安福县| 灌云县| 南皮县| 兴仁县| 织金县| 芷江| 台安县| 定陶县| 南城县| 武山县| 新邵县| 渝北区| 苍溪县| 麻阳| 晋江市| 临城县| 庄浪县| 天长市| 桃园市| 芜湖县| 南华县| 嘉定区| 玉门市| 徐州市| 大邑县| 青神县| 瑞金市| 镇平县| 郴州市| 新乡市| 青冈县| 武平县| 蒲城县| 海宁市| 彭泽县| 丰城市| 蓬莱市| 京山县|