Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode, iPhone: How to detect simulator target at compile time?

Tags:

I wonder if, when building an iPhone app for the Simulator, there are special DEFINEs added that allow me to conditionally compile for this case?

If not, I'll have to add my own targets for this case, but I'd rather have an automatic way of detection.

Alternatively, is there a dynamic way to know when my code runs on the Simulator, I mean something that's documented? I've been searching the docs for a while now but had no luck yet.

like image 428
Thomas Tempelmann Avatar asked Jun 09 '10 15:06

Thomas Tempelmann


People also ask

Does iOS simulator simulate performance?

The simulator does a really lousy job of indicating app performance. In fact it doesn't try. For most things the simulator is much, much faster than an iOS device. It runs your code on an x86 processor, which is much faster than the ARM and has many times more memory.

How do you choose a simulated device as a destination?

For iOS, tvOS, and watchOS apps, you can choose a simulated device, under [Platform] Simulators, from the run destination menu next to the scheme menu in the toolbar. To add additional simulators of a product family running older versions of the operating system, choose Add Additional Simulators.

How do I use iPhone as Xcode simulator?

To run your app in Simulator, choose an iOS simulator—for example, iPhone 6 Plus, iPad Air, or iPhone 6 + Apple Watch - 38mm—from the Xcode scheme pop-up menu, and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator on your Mac screen, as shown in Figure 1-1.

How do I test my website in Xcode iPhone simulator?

Viewing & Testing. When you're in the simulator, click open Safari, click on the URL bar, and you can paste the testing URL using ^⌘V (Edit > Paste Text), then hit enter.


1 Answers

For compile-time check you need TARGET_IPHONE_SIMULATOR defined in TargetConditionals.h

#if TARGET_IPHONE_SIMULATOR // Simulator code #endif 

For run-time check you can use for example -model method in UIDevice. For iPhone simulator it returns iPhone Simulator string (not sure about iPad simulator though)

like image 51
Vladimir Avatar answered Sep 26 '22 00:09

Vladimir