For some reasons I evaluate the option to exchange data between my iOS-App and my C++-Lib (used by the iOS-App) by file.
C++ (works fine on a local machine):
void LibFacadeTest::testFileAccess()
{
this->log->info("start testFileAccess");
char filename[] = "./test.txt";
std::string result;
LibFacade *e = new LibFacade();
try
{
result = e->testFileAccess(filename);
}
catch(...)
{
this->log->error("error");
}
this->log->info("Result:" + result);
delete(e);
}
Recompiled for ARM and run on device I can see that the filename parameter is passed correctly (via log), but nothing is returned.
Here is the Objective-C code:
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];
A bit quick and dirty, but what I can see is that there no file has been created on device although the lib could be used.
My question:
Are there any restrictions to access a device file system from an included C++ lib? Do I have to use any special directories for file exchange?
Your application is “sandboxed”, meaning that it cannot access files outside of its temporary and document file space.
"./test.txt"is outside the “sandbox area”, so iOS correctly does not let you access that file. In a nutshell, if you would like to transfer data using temporary files, you’d need something like this for a file name:This document provides further reading on the subject.