【发布时间】:2011-05-23 06:02:07
【问题描述】:
我正在使用 Dropbox API 并在应用程序文件夹中下载文件。
我可以从文档目录中查看表中的文件列表。如何从此表格视图中读取照片或文件?
那么 iPhone 呢?可以直接访问文件夹吗?
【问题讨论】:
-
应用程序文件夹是沙盒的一部分。所以你不能直接把任何物品放进去。您可以先将文件添加到 xCode proj(NSbundle)。那么只能访问
我正在使用 Dropbox API 并在应用程序文件夹中下载文件。
我可以从文档目录中查看表中的文件列表。如何从此表格视图中读取照片或文件?
那么 iPhone 呢?可以直接访问文件夹吗?
【问题讨论】:
这是比较常用的获取文档目录的方法——
NSArray *searchResults = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [searchResults objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
您可以使用NSFileManager 来检查目录的内容。你可以看看contentsOfDirectoryAtPath:error:方法。
访问文档文件夹 -
NSDictionary *theCatalogInfo=nil;
NSString *theCatalogFilePath = [NSString stringWithFormat:@"%@/Documents/",NSHomeDirectory()];
theCatalogFilePath = [theCatalogFilePath stringByAppendingString:@"File Name"];
if(nil!=theCatalogFilePath)
{
theCatalogInfo=[[NSDictionary alloc]initWithContentsOfFile:theCatalogFilePath];
}
return theCatalogInfo;
【讨论】: