tags:

views:

38

answers:

2

Hi

I am building a Web application.

When I am testing it on a simulator, I want to typically use a local loop back URL e.g. localhost because the test may mess up the data on a real server. When I want to test/release on a Device, I want to use a real server.

I can change the value manually, of course, but it is easy to forget to change. I am looking for an automatic solution if it is possible.

E.g. if I am using Debug or just Run, I know that I could use DEBUG flag that is set by the Project settings to produce different codes.

i.e.

#ifdef DEBUG
    kURL = @"http://localhost/xyx"
#else
    kURL = @"http://realserver/xyz"
#endif

Since the flag is automatically set by the Xcode (I still choose whether to Run or Debug from the Menu), it relieves me from manually setting the flag in the code myself regarding whether it is run for Debug or Run.

Although this is useful, the DEBUG flag is no use to detect either it is run on a simulator or on a device.

I don't know whether there is any flag defined to identify whether it is running on a simulator or a device (or different versions/names of SDKs, since it seems that they use different SDKs), that I could use to instruct the code to use different URLs.

Any idea?

Thanks.

+1  A: 

You can use TARGET_IPHONE_SIMULATOR and TARGET_OS_IPHONE (I think)

TheNextman
Isn't that more for compile-time and not run-time?
Stephen Furlani
He asked if there was a compiler flag; and that's it :)
TheNextman
Thanks, folks. The Nextman was right. I asked for compiler flags.Actually, this was listed very early in the Apple documentation, which I must have read ages ago and forgotten all about it until I am in need of it!http://developer.apple.com/iphone/library/documentation/xcode/conceptual/iphone_development/115-Configuring_Applications/configuring_applications.html
Yoichi
@TheNextman, lol duh :)
Stephen Furlani
A: 

A simple Google search came up with this: "iphone simulator device detect"

Check out the UIDevice class.

Stephen Furlani
Thanks. It is a useful information, too. Particularly if I need to change certain things in a released code, depending on what device the app is running. Although I can use it, too, I prefer the TARGET_IPHONE_SIMULATOR for the current need.
Yoichi