2016-09-02 7 views
0

iOS用のサウンドレコーダーをネイティブC++で作成しています。私はFoundation APIを使用できません。iOS - C++で書き込み可能なパスを取得

私はこのような何かが必要ですiPhone上の書き込み可能なパスを取得するには

recordFilePath = 
(CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.caf"]; 

を。

ありがとうございました。 OP、オブジェクティブC++を使用した例をコメントした後

+0

をそのは、iPhone上で実行するものであれば、あなたが財団のAPIを使用することはできませんなぜあなたは説明できますか? – abidon

+0

これはCocos2d-xでコンパイルする必要があるためです。 – CttPla

+0

これは私が探していたものだと思いますが、まだ有効な場合: http://stackoverflow.com/questions/13469342/using-c-to-access-documents-folder-on-ios – CttPla

答えて

0

もちろん、話すことはできますが自信を持ってこれは私のクライアントのための仕事であり、彼は外部の機能や橋渡しを要求しなかった。だから私はFoundationへの参照なしにオーディオキューコンポーネントを構築しなければならなかった。レコードの

、私はちょうどこれをやってsuccedeed:

 const char *home = getenv("HOME"); 
     const char *subdir = "/Documents/"; 
     const char *file = "recordedFile.caf"; 

     char *recPath = (char*)(calloc(strlen(home) + strlen(subdir) 
           + strlen(file) + 1, sizeof(char))); 

     strcpy(recPath, home); // copy string one into the result. 
     strcat(recPath, subdir); // append string two to the result. 
     strcat(recPath, file); // append string three to the result. 

     //recordFilePath is our CFStringRef 
     recordFilePath = CFStringCreateWithCString(0, recPath, kCFStringEncodingUTF8); 

     //recorder is an AQRecorder class like the one from SpeakHere code sample 
      recorder->StartRecord(recordFilePath); 
0

Utils.hpp:

#pragma once 
#include <string> 

std::string temporaryFilePath(const std::string &filename) 

Utils.mm:

#import "Utils.hpp" 
#import <Foundation/Foundation.h> 

std::string temporaryFilePath(const std::string &filename) 
{ 
    NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithUTF8String:filename.c_str()]]; 
    const char *rawFilePath = [filePath UTF8String]; 
    return rawFilePath; 
} 

WhereverYouWant.cpp:

#include "Utils.hpp" 

... 

std::string recordFilePath = temporaryFilePath("recordedFile.caf"); 
関連する問題