2012-08-09 116 views
0

在我開始之前,我需要強調的是,我已經看過處理文檔目錄的每一篇文章。iOS 5.1模擬器「文檔」鬼目錄

因此,我會盡力解決我的問題,以便更好地幫助您。

我正在開發針對5.1的iOS應用程序。我正在使用XCode 4.4.1和iOS模擬器版本5.1(272.21)。

這是我的理解是,當一個應用程序被安裝在模擬器中,它的目錄結構

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID] 

當我運行我的應用程序這是正確地反映在映射。

而且我能夠成功地創建和使用下面的代碼

NSString *tmpDir = NSTemporaryDirectory(); 

導致以下路徑使用一個臨時目錄

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/tmp 

的問題開始出現時,我想工作Documents應該在的目錄

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/Documents 

下面的代碼檢查是否存在該路徑,然後使用NSLog記錄它,即使它說存在導航到該位置返回一個文件未找到。

+ (NSString *) currentPath{ 

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentPath = [searchPaths objectAtIndex:0]; 

searchPaths=nil; 

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:documentPath]; 

if (fileExists == TRUE) { 
    NSLog(@" %@ already exists",documentPath); 
} else { 

    NSLog(@"doesn't exists"); 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSError *error; 

    if(![fileManager createDirectoryAtPath:documentPath withIntermediateDirectories:true attributes:nil error:&error]) 
    { 
     NSLog(@"Couldn't create documents directory %@",error); 

    } 



} 

return documentPath; 

} 

結果是NSLog的線路是:

2012-08-09 23:12:09.813 AMM[22656:c07] /Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B/Documents already exists 

在終端

> pwd 
/Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B 
>ls -lsa 
    total 0 
    0 drwxr-xr-x 5 fotis 170 Aug 9 23:12 . 
    0 drwxr-xr-x 3 fotis 102 Aug 9 22:50 .. 
    0 drwxr-xr-x 30 fotis 1020 Aug 9 23:12 AMM.app 
    0 drwxr-xr-x 4 fotis 136 Aug 9 22:50 Library 
    0 drwxr-xr-x 4 fotis 136 Aug 9 22:51 tmp 

正如你看到的,我文件 ghost目錄是不存在的。對於我來說,我無法理解這一切背後的魔力。有一點需要注意的是,我在我的應用程序委託的「-didFinishLaunchingWithOptions」方法中運行這個,因爲我正在做一些初始化。

任何想法?

回答

0

該模擬器在該場地上有點笨重,它曾經是當你的應用程序沒有在模擬器上運行時甚至找不到模擬沙箱。無論如何,你不應該擔心創建的文件夾,它將永遠存在於設備上(也是模擬器,因爲你還沒有試圖刪除它在應用程序或Finder中)

0

我不' t知道我是否可以反對我自己的問題,但這裏是燒烤。

事實證明,我的初始化過程的一部分是刪除一些文件從文件目錄。

因此,如果有人想知道缺少的路徑,請確保您的斜槓「/」是正確的,並且您的雲彩(*)DO NOT包含您的根(Documents /)文件夾。

然而,什麼是奇怪的事實是,我的'壞'的代碼能夠從它的路徑中刪除這個(對於什麼是值得的,應用程序相關的)目錄。