Iphone 数据交换目标-C与C++;基于文件
出于某些原因,我评估了在iOS应用程序和我的C++-Lib(由iOS应用程序使用)之间按文件交换数据的选项 C++(在本地计算机上运行良好): 为ARM重新编译并在设备上运行,我可以看到文件名参数传递正确(通过日志),但没有返回任何内容 以下是Objective-C代码:Iphone 数据交换目标-C与C++;基于文件,iphone,objective-c,ios,objective-c++,Iphone,Objective C,Ios,Objective C++,出于某些原因,我评估了在iOS应用程序和我的C++-Lib(由iOS应用程序使用)之间按文件交换数据的选项 C++(在本地计算机上运行良好): 为ARM重新编译并在设备上运行,我可以看到文件名参数传递正确(通过日志),但没有返回任何内容 以下是Objective-C代码: LibFacade *tlb = new LibFacade(); char *testName = "blub.txt"; std::string str = tlb->testFileAccess(testName
LibFacade *tlb = new LibFacade();
char *testName = "blub.txt";
std::string str = tlb->testFileAccess(testName);
// Check, if file exists
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: @"blub.txt" ] == YES)
NSLog (@"File exists");
else
NSLog (@"File not found");
NSError *error = nil;
NSString *myString = [NSString stringWithContentsOfFile:@"blub.txt" encoding:NSUTF8StringEncoding error:&error];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:myString
delegate:nil cancelButtonTitle:nil destructiveButtonTitle:myString otherButtonTitles:nil];
[actionSheet showInView:self.view];
有点快和脏,但我可以看到,虽然可以使用lib,但设备上没有创建任何文件
我的问题:
是否有限制从包含的C++ LIB访问设备文件系统?我必须使用任何特殊目录进行文件交换吗?您的应用程序处于“沙盒”状态,这意味着它无法访问临时和文档文件空间之外的文件“/test.txt”
位于“沙箱区域”之外,因此iOS不允许您正确访问该文件。简言之,如果您想使用临时文件传输数据,则需要这样的文件名:
NSString *tempDirectoryName =
[NSTemporaryDirectory() stringByAppendingPathComponent:@"test.txt"];
提供关于该主题的进一步阅读
NSString *tempDirectoryName =
[NSTemporaryDirectory() stringByAppendingPathComponent:@"test.txt"];