2012-08-23 119 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"];