我正在使用 native C++ 为 iOS 编写录音机,但我无法使用 Foundation API。
我需要这样的东西:
recordFilePath =
(CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.caf"];
在 iPhone 上获取可写路径。
非常感谢。
最佳答案
当然可以,但自信地说,这是我客户的任务,他不要求核心类中涉及 Foundation 的任何外部功能或桥梁或任何东西。所以我不得不构建一个不引用 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);
关于c++ - iOS - 在 C++ 中获取可写路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39288270/