Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to obtain the local IP address from a preprocessor DEFINE in Objective-C?

This is probably a long shot but doesn't hurt to ask...
Do you think it's possible to obtain the IP address of the build host when building for iOS in Objective-C under xcode?
It'd be useful for my testing if it were possible.
For example:

NSString* backendUrl = [NSString stringWithFormat:@"http://%@:5000/", HOST_IP];

Where I would expect HOST_IP (if there was something like that) to be something like this, but of course automatically controlled at build time to hold the correct IP:

#define HOST_IP @"172.76.77.5"
like image 582
Ran Avatar asked Oct 30 '11 12:10

Ran


1 Answers

No convenient solution, but here are some options to consider.

  1. In your #define, type your computer's Host-Name (if it's on a LAN) - http://mylaptop:5000/ or simply sign up to a free domain @ http://www.no-ip.com/

  2. If it's necessary to specifically have a #define macro that contains your IP Address, you could simply write a small bash script that updates the defined ip in your .m/.cpp/.h file or whatever holds this #define. then you can add the script as a pre-build phase, or just run the script when you know that the IP Address has changed. although I admit it's kinda hackish.

like image 77
Alon Amir Avatar answered Oct 29 '22 01:10

Alon Amir