Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compile when running in Simulator as opposed to on a device

Is there a compiler directive I can use to compile a different line of code when targetting the simulator as opposed to my device. Something like:

# IF SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; # ELSE [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; # END 

EDIT

Direct link to docs.

like image 650
Codebeef Avatar asked May 14 '09 18:05

Codebeef


2 Answers

#if TARGET_IPHONE_SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; #else [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; #endif 
like image 111
Codebeef Avatar answered Sep 17 '22 14:09

Codebeef


Update: (Deprecated/Obsolete) This only worked for a few years, and does not work any more. (10+ years later)

For the record, here's another method which Apple uses in some of their official Sample Code:

#if TARGET_CPU_ARM   // Only executes on an iPhone or iPod touch device   [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; #else   // Only executes on the Simulator   [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; #endif 
like image 24
Elliot Avatar answered Sep 18 '22 14:09

Elliot