Answering the question “what environment variables are available on the iPhone”

Just wrote a simple program to use NSProcessInfo to dump the environment variables on my iPhone. And I found the iPhone running my app standalone predefines the following environment variables:

SHELL = /bin/sh
CFFIXED_USER_HOME = /private/var/mobile/Applications/[UUID]
PATH = /usr/bin:/bin:/user/sbin:/sbin
TMPDIR = /private/var/mobile/Applications/[UUID]/tmp
__CF_USER_TEXT_ENCODING = 0x1F5:0:0
USER = mobile
LOGNAME = mobile
HOME = /private/var/mobile/Applications/[UUID]

The [UUID] is the UUID for your application, to differentiate the directory for your application from the directory used by other applications.


I find it interesting because it means that if you have some Unix C code that attempts (for example) to find the location of a file without using the various search methods available in iOS Cocoa, you can do it. For example, you can change the working directory to the documents folder by writing:

chdir(getenv("HOME"));
chdir("Documents");

(The standard iPhone directories are documented here: The Application Runtime Environment, under “The File System”.)

That can be quite useful…

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s