iOS — получите доступный для записи путь в переполнении стека

Я пишу звукозапись для iOS на родном C ++ и не могу использовать Foundation API.

Мне нужно что-то вроде этого:

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

Чтобы получить доступный для записи путь на iPhone.

Огромное спасибо.

0

Решение

Конечно, вы можете, но, говоря уверенно, это задача для моего клиента, и он не просил никаких внешних функций или мостов или чего-либо еще, связанного с Foundation в основных классах. Поэтому мне пришлось создать компонент audioqueue без ссылок на Foundation.

Для справки, я преуспел, просто сделав это:

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

Другие решения

После комментирования OP, пример с использованием 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");
0