dokun1
dokun1

Reputation: 2110

Get iPhone directory path in C++

I am using a C++ library from an Objective-C layer. I want to be able to access this path, or at least it's container identifying string, directly in the C++ library.

(NB: In production we are able to pass the identifier from the Objective-C layer, but this is to try and get the path directly in CI)

For example, if I get the NSDocumentDirectory path in Objective-C, the path is easy:

/var/mobile/Containers/Data/Application/93C788E8-3F76-4DD2-BC5F-7980BE9970C7/Documents

I could strip out the GUID (93C788E8-3F76-4DD2-BC5F-7980BE9970C7) from this path and pass it, but I need to be able to generate it purely in C++. Our CI is running our unit test suite directly on a device instead of a simulator. I know that this is basically a unix command, but I've spent my morning snooping around, and coming up empty. Any ideas where to look?

Upvotes: 1

Views: 2313

Answers (1)

Simon Kraemer
Simon Kraemer

Reputation: 5680

You can use getenv("HOME"); to get the path to your application's directory.

Taking your example into account this should return /var/mobile/Containers/Data/Application/93C788E8-3F76-4DD2-BC5F-7980BE9970C7/.

Then you can extract the GUID from this path.

The idea to this was taken from https://stackoverflow.com/a/17284816/4181011

Upvotes: 3

Related Questions