Reputation: 12261
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.
Upvotes: 0
Views: 176
Reputation: 6856
A simple Google search came up with this: "iphone simulator device detect"
Check out the UIDevice class.
Upvotes: 0
Reputation: 12566
You can use TARGET_IPHONE_SIMULATOR and TARGET_OS_IPHONE (I think)
Upvotes: 1