I often work on iOS projects alongside a development server, which is always running on the same machine that I'm using to build the app. A typical scenario is that I have a rails app running on http://localhost:3000 and I'm testing on the device. In order to test on the device, I need a resolved IP address so that my app can talk to my development server on the local network.
I know that I can use GCC_PREPROCESSOR_DEFINITIONS to set some environment variable into a preprocessor macro, and I know that I can get the build machine's IP address by running ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}' in a bash script.
What I want to do is define MY_SERVER_URL in GCC_PREPROCESSOR_DEFINITIONS using a value such as '@"http://${BUILD_MACHINE_IP_ADDRESS}:3000"', but what I can't figure out is how to set ${BUILD_MACHINE_IP_ADDRESS} using the ifconfig script above.
I have considered editing a configuration file using a run script build phase, but the ramifications of a change like this are irritating. For example, I wouldn't want the file included in source control because my IP address changes frequently and it would cause conflicts. But I would need it to be included in the project file so that the application can access it. This would lead to a file that's required for the project to build but isn't included in the source control, which is ugly.
I've also tried running export BUILD_MACHINE_IP_ADDRESS=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}` in a run script build phase but that doesn't yield a result.
BUILD_MACHINE_IP_ADDRESS=$(ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}')exportthat variable on command line or add it to your profile file to make it globally available every time you open a terminal.