2016-09-02 2 views
0

Ich schreibe einen Sound Recorder für iOS in nativem C++ und ich kann die Foundation API nicht verwenden.iOS - Erhalte einen beschreibbaren Pfad in C++

Ich brauche etwas wie folgt aus:

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

Um einen beschreibbaren Pfad auf dem iPhone zu bekommen.

Vielen Dank.

+0

Können Sie erklären, warum Sie nicht die Foundation-API verwenden können, wenn seine auf einem iPhone laufen soll? – abidon

+0

Weil es mit Cocos2d-x kompilieren muss. – CttPla

+0

Ich denke, das ist, was ich gesucht habe, wenn noch gültig: http://StackOverflow.com/Questions/13469342/using-c-to-access-documents-folder-on-ios – CttPla

Antwort

0

Sicher kannst du, aber sprechen Ich bin zuversichtlich, dass dies eine Aufgabe für einen Kunden von mir ist, und er hat keine externen Funktionen oder Brücken oder was auch immer mit der Foundation in den Kernklassen angefordert. Also musste ich eine Audioqueue-Komponente ohne Bezug auf Foundation erstellen.

Für das Protokoll, ich succedeed dies nur tun:

 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

Nach OP Kommentierung, die ein Beispiel unter Verwendung von Objective-C++:

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"); 
Verwandte Themen