2013-04-30 23 views
-1

我已經從在應用程序/文件夾的用戶存儲圖像的應用程序,我做了下面的代碼確定路徑保存它:使用目錄來存儲信息,並保持這些信息在應用程序更新

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docs = [paths objectAtIndex:0]; 
    NSString *imageFilename = [[[[NSNumber alloc] initWithInteger:self.nextID] stringValue] stringByAppendingFormat:@".jpg"]; 
    NSString *dirPath = [docs stringByAppendingFormat:@"/Photos/"]; 
    imagePath = [dirPath stringByAppendingString:imageFilename]; 

它給了我類似(在模擬器)的路徑: /var/mobile/Applications/C9C43CFD-6A5F-40CF-8BAE-20496B5A544A/Documents/Photos/1.jpg

我保存這個路徑當我需要時顯示此圖像。

我的問題是,當我在應用程序商店發送更新時,更新應用程序後,它不能再顯示圖像。 我的理解是當更新AppStore中的應用程序時,Documents文件夾不能更改。

我可能的原因是它的應用程序文件夾和Documentar之間的名稱已更改,從AppStore更新應用程序版本時它是真的嗎?

有沒有人有任何想法?有什麼辦法來測試這個應用程序更新本地?

感謝

回答

1

您需要保存Documents目錄後的相對路徑,而不是絕對路徑。應用程序的目錄可以在更新期間更改,但應用程序沙箱內的結構不會更改。

此外,還有一個稍微好一點的方式來建立自己的路徑:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docs = [paths objectAtIndex:0]; 
NSString *imageFilename = [NSString stringWithFormat:@"%d.jpg", self.nextID]; 
NSString *dirPath = [docs stringByAppendingPathComponent:@"Photos"]; 
imagePath = [dirPath stringByAppendingPathComponent:imageFilename]; 
0

當應用程序被從App Store更新,文檔目錄的內容不變。應用程序包及其所有內容均替換爲新版本,但「文檔」文件夾是在應用程序版本之間存儲內容的安全場所。