【问题标题】:Application's Document folder in iphoneiphone中应用程序的文档文件夹
【发布时间】:2011-05-23 06:02:07
【问题描述】:

我正在使用 Dropbox API 并在应用程序文件夹中下载文件。

我可以从文档目录中查看表中的文件列表。如何从此表格视图中读取照片或文件?

那么 iPhone 呢?可以直接访问文件夹吗?

【问题讨论】:

  • 应用程序文件夹是沙盒的一部分。所以你不能直接把任何物品放进去。您可以先将文件添加到 xCode proj(NSbundle)。那么只能访问

标签: iphone dropbox


【解决方案1】:

这是比较常用的获取文档目录的方法——

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

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];

您可以使用NSFileManager 来检查目录的内容。你可以看看contentsOfDirectoryAtPath:error:方法。

【讨论】:

  • ok.意味着我无法在没有代码的情况下访问 iphone 中的文档目录
  • 没有。这是可能的。看this。
  • 好的..如果我想将照片上传到保管箱。我应该使用图像选择器还是可以将图像从相机保存到文件夹?
  • 使用UIImagePicker处理imagePicker:didFinishPickingMediaWithInfo:中的保存部分。
  • 您必须保存它。更好地解释here。
【解决方案2】:

访问文档文件夹 -

NSDictionary *theCatalogInfo=nil;
NSString *theCatalogFilePath = [NSString stringWithFormat:@"%@/Documents/",NSHomeDirectory()];
theCatalogFilePath = [theCatalogFilePath stringByAppendingString:@"File Name"];
if(nil!=theCatalogFilePath)
{


    theCatalogInfo=[[NSDictionary alloc]initWithContentsOfFile:theCatalogFilePath];

}

return theCatalogInfo;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 2010-11-28
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多