2012-01-04 1 views
3

몇 가지 이유로 iOS-App과 C++ Lib (iOS-App에서 사용) 사이의 데이터 교환 옵션을 파일별로 평가합니다.데이터 교환 Objective-C vs. C++ 파일 기반

C++는 (로컬 컴퓨터에서 잘 작동) :

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); 
    } 

는 ARM 용으로 다시 컴파일 내가 파일 이름 매개 변수 (로그를 통해) 제대로 전달되는 것을 볼 수 있습니다 장치에서 실행하지만 아무것도 반환되지 않습니다. 여기

은 목표 - C 코드 :

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에서 장치 파일 시스템에 액세스하는 데 제한이 있습니까? 파일 교환을 위해 특별한 디렉토리를 사용해야합니까?

답변

4

응용 프로그램이 "샌드 박스 처리"되어있어 임시 파일 및 문서 파일 공간 외부의 파일에 액세스 할 수 없습니다. "./test.txt"이 "샌드 박스 영역"외부에 있으므로 iOS에서 해당 파일에 액세스 할 수 없습니다. 임시 파일을 사용하여 데이터를 전송하려는 경우 간단히 말해서, 당신은 파일 이름이 같은 것을 필요할 것 :

NSString *tempDirectoryName = 
    [NSTemporaryDirectory() stringByAppendingPathComponent:@"test.txt"]; 

This document이 주제에 대한 추가 읽기를 제공

.