iOS 5.1模拟器“文档”重影目录
在开始之前,我需要强调一个事实,我已经看过了每一篇涉及文档目录的文章 所以我会尽力解决我的问题,以便更好地帮助你帮助我 我正在开发面向5.1的iOS应用程序。我使用的是XCode 4.4.1和iOS模拟器版本5.1 272.21 据我所知,当在模拟器中安装应用程序时,其目录结构映射到iOS 5.1模拟器“文档”重影目录,ios,simulator,documents,Ios,Simulator,Documents,在开始之前,我需要强调一个事实,我已经看过了每一篇涉及文档目录的文章 所以我会尽力解决我的问题,以便更好地帮助你帮助我 我正在开发面向5.1的iOS应用程序。我使用的是XCode 4.4.1和iOS模拟器版本5.1 272.21 据我所知,当在模拟器中安装应用程序时,其目录结构映射到 /Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID] 这在我运行应用程序时得到了正确的反映 此外,
/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]
这在我运行应用程序时得到了正确的反映
此外,我能够使用以下代码成功地创建和使用临时目录
NSString *tmpDir = NSTemporaryDirectory();
这将导致以下路径
/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/tmp
当我想处理应该在其中的Documents目录时,问题开始出现
/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/Documents
下面的代码检查该路径是否存在,然后使用NSLog记录该路径,即使它说它存在,导航到该位置也会返回一个未找到的文件
+ (NSString *) currentPath{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
searchPaths=nil;
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:documentPath];
if (fileExists == TRUE) {
NSLog(@" %@ already exists",documentPath);
} else {
NSLog(@"doesn't exists");
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if(![fileManager createDirectoryAtPath:documentPath withIntermediateDirectories:true attributes:nil error:&error])
{
NSLog(@"Couldn't create documents directory %@",error);
}
}
return documentPath;
}
NSLog行的结果是:
2012-08-09 23:12:09.813 AMM[22656:c07] /Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B/Documents already exists
在候机楼
> pwd
/Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B
>ls -lsa
total 0
0 drwxr-xr-x 5 fotis 170 Aug 9 23:12 .
0 drwxr-xr-x 3 fotis 102 Aug 9 22:50 ..
0 drwxr-xr-x 30 fotis 1020 Aug 9 23:12 AMM.app
0 drwxr-xr-x 4 fotis 136 Aug 9 22:50 Library
0 drwxr-xr-x 4 fotis 136 Aug 9 22:51 tmp
如您所见,我的文档鬼目录不在那里。就我的一生而言,我无法理解这一切背后的魔力。需要注意的一点是,我正在我的app委托的-didfishlaunchingwithoptions方法中运行这个,因为我正在那里进行一些初始化
有什么想法吗?在那个地方,模拟器有点笨重,过去,当你的应用程序没有在模拟器上运行时,你甚至找不到模拟沙盒。无论如何,您不必担心创建Documents文件夹,它将始终存在于设备和模拟器上,因为您没有尝试在app或Finder中删除它我不知道是否可以否决我自己的问题,但这里是grill 我的初始化过程的一部分是从Documents目录中删除一些文件 因此,对于任何想知道丢失路径的人,请确保斜杠/正确,并且globs*不包括根文档/文件夹 然而,奇怪的是,我的“坏”代码能够从其路径中删除这个有价值的依赖于应用程序的目录