schmidt9 schmidt9 - 3 months ago 36
iOS Question

Create directory/file in iOS using C++

Is it possible to create in app's home dir (Documents or Library) dir/file using C++ code? I tried

system()
and
posix_spawn()
, which work on Simulator, but fail or real device (eg. running
mkdir
). Core Foundation methods seem to give only read, not write possibility too.

Answer

You can get the home directory using the Core Foundation library's CFCopyHomeDirectoryURL() function. (This is a C function, no Objective-C required.) Using the CFURL accessors, you can pull the path from that and use it with standard C++ or C/POSIX file I/O functions. Or you can use Core Foundation for I/O directly.

You can't used posix_spawn or system or fork/exec* in iOS due to sandboxing. No shell scripts either.