我的应用程序的文档目录包含子文件夹和文件,如下所示:
我正在尝试使用以下代码检索要显示的文档:
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/