使用C ++访问iOS上的Documents文件夹

我想知道是否有一种方法可以在iOS上使用C ++来获得对Documents文件夹的引用(即,不使用Objective-C中的任何代码;这是因为它是一个只能在C ++中实现的框架,可以作为库添加在iOS项目中)。

请,如果可能的话,在你的答案中提供代码。

使用下面的代码,我可以访问我的应用程序的caching文件夹。 我想,“/图书馆/文件”,或其他一些文件夹。

char *home = getenv("HOME"); char *subdir = "/Library/Caches/subdir"; 

home + subdir =完整path

接下来,用完整的path,你可以做一些常用的事情来读写C ++

是的,你可以访问普通的Unix API。 请参阅苹果iOS手册 。

获取path(使用Cocoa API),然后使用和API将其转换为与C ++string兼容的表示forms,例如: CFStringGetFileSystemRepresentationCFURLGetFileSystemRepresentation-[NSString fileSystemRepresentation]

就像是:

 // you may need to wrap this in an autorelease pool NSArray * paths(NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)); const char* const path([[paths objectAtIndex:0] fileSystemRepresentation]); if (0 == fsrep) { uh-oh } const std::string result(path); 

然后你可以简单地把它放在它自己的ObjC ++平移中,并从函数返回result (这对你其余的C ++源代码是可见的)。