2012-08-23 62 views
0

我在我的應用程序中集成了Dropbox。我已經將它顯示給用戶,他們可以選擇要下載的文件。我知道我需要調用這一行,但我不知道iPhone上的本地文件路徑是什麼。它只需要是臨時的,因爲一旦我有文本文件,我會處理它...我的問題是什麼是本地文件路徑。先謝謝你。iPhone本地文件路徑

[[self restClient] loadFile:[filePaths objectAtIndex:indexPath.row] intoPath:localPath] 

更新根據回答波紋管:::仍然沒有工作

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSString *localPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:[filePaths objectAtIndex:indexPath.row]]; 
    [[self restClient] loadFile:[filePaths objectAtIndex:indexPath.row] intoPath:localPath]; 
    NSLog(@"%@",[NSString stringWithContentsOfFile:localPath encoding:NSUTF8StringEncoding error:nil]); 

} 

回答

0

你通常只使用本地文件目錄。

試試這個:

NSString *localPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:[filePaths objectAtIndex:indexPath.row]];

+0

終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因:「*** - [NSPathStore2 stringByAppendingString:]:無參數」 – BDGapps

+0

看看我如何使用它上面... – BDGapps

+0

你確定' [filePaths objectAtIndex:indexPath.row]'不是null? – Sebrassi

0

你可能在尋找:

NSString * tempPath = [NSSearchPathForDirectoriesInDomains(NSTemporaryDirectory(), NSUserDomainMask, YES) objectAtIndex:0]; 
NSString * yourFile = [filePaths objectAtIndex:indexPath.row]; 

if(yourFile != nil) { 
    NSString * filePath = [tempPath stringByAppendingPathComponent:yourFile]; 
} 
else { 
    // Check your file 
} 
0

對於需要一個臨時目錄中的Unix存在很長時間Objective-C的前歷史原因。因此,以我們的語言獲取臨時目錄的方法是在使用confstr的現有Unix方法的基礎上制定的。爲了您的方便,它也在NSPathUtilities中。

NSString *tmpDirectory = NSTemporaryDirectory(); 
NSString *tmpFile = [tmpDirectory stringByAppendingPathComponent:@"temp.txt"];