CttPla CttPla - 1 year ago 103
C++ Question

iOS - Get a writable path in C++

I'm writing a sound recorder for iOS in native C++ and i cannot use the Foundation API.

I need something like this:

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

To get a writable path on the iPhone.

Thank you so much.

Answer Source

Sure you can, but speaking confidently this is a task for a client of mine and he requested no external functions or bridges or whatever involving Foundation in the core classes. So i had to built an audioqueue component without references to Foundation.

For the record, i succedeed just doing this:

        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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download