2012-01-04 12 views
3

何らかの理由で、iOS-Appと私のC++-Lib(iOS-Appで使用)間でデータを交換するオプションを評価します。データ交換Objective-CとC++のファイルベース

C++(ローカルマシン上で正常に動作します):

ARM用に再コンパイル
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); 
    } 

と、デバイス上で実行する私は、ファイル名パラメータは、(ログを経由して)正しく渡されますが、何も返されないことがわかります。ここで

は、Objective-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]; 

Aは、迅速かつダーティビットが、何私が見ることができることは、LIBを使用することができるがそこには、ファイルがデバイス上に作成されていないということです。

私の質問: 付属のC++ライブラリからデバイスファイルシステムにアクセスするための制限はありますか?ファイル交換のために特別なディレクトリを使用する必要がありますか?

答えて

4

アプリケーションは「サンドボックス化」されています。つまり、一時ファイルとドキュメントファイルの領域外のファイルにアクセスすることはできません。 "./test.txt"は「サンドボックス領域」の外側にあるため、iOSではそのファイルにアクセスできません。あなたは一時ファイルを使用してデータを転送したい場合は一言で言えば、あなたは、ファイル名に、このようなものが必要だろう:

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

This documentは、件名に、さらに読みを提供します。

関連する問題