简体   繁体   中英

How to use different URLs for Simulator and Device

I am building a Web application.

When I am testing it on a simulator, I want to typically use a local loop back URL eg 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.

Eg 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.

ie

#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.

您可以使用TARGET_IPHONE_SIMULATOR和TARGET_OS_IPHONE(我认为)

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

Check out the UIDevice class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM