ios - 文档目录在设备上表现得好像是空的,但在模拟器上却不是

标签 ios xcode directory document

我的应用程序的文档目录包含子文件夹和文件,如下所示:

Shot of app's Document folder

我正在尝试使用以下代码检索要显示的文档:

NSMutableArray *documentData = [[NSMutableArray alloc] initWithCapacity:0];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [directoryPaths objectAtIndex:0];

NSError *error = nil;
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];

NSString *myFolder = [documentsDirectory stringByAppendingPathComponent:@"Downloads/Diagrams"];
NSLog(@"rostering at: %@", myFolder);

NSArray *folderContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:myFolder error:&error];
NSLog(@"contetns of diagrams folder: %@", folderContents);

当我在 iPad 上运行它时,没有获取任何文档进行显示,控制台的输出是:

contetns of diagrams folder: (null)

当我在模拟器上运行时,文档显示正常,输出为:

contetns of diagrams folder: (
"6901-6905.doc",
"7100-71101.doc",
"1234-5678.doc"

)

对于可能导致这种情况的原因,是否有任何明显的解释?谢谢。

最佳答案

您应该知道,模拟器不区分大小写,而设备则区分大小写。

关于ios - 文档目录在设备上表现得好像是空的,但在模拟器上却不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13518666/

相关文章:

java - java读取目录中的文件并存储其在目录中的偏移量

ios - 如何在 Storyboard中选择多个 Controller ?

ios - 在响应式(Reactive)编程中创建静态流是个坏主意吗?

ios - 如何知道我的 iOS 应用程序是否具有正确的 Bundle ID?

python - 在python中按顺序重命名文件

c++ - 在测试工具下获取当前可执行目录失败

ios - Apple 新的 Kids Section 家长控制问题

iphone - SKProductsResponse 对于应用内购买没有响应

objective-c - 在 XCode + Objective-C 中链接用 C 编写的库

xcode - 在将 iOS 应用程序上传到 AppStore 之前尝试验证该应用程序时出错