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

后端 未结 3 478
[愿得一人]
[愿得一人] 2021-02-01 03:06

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         


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-01 03:56

    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
    

提交回复
热议问题