在Simulator中运行时的条件编译,而不是在设备上运行 [英] Conditional compile when running in Simulator as opposed to on a device

查看:122
本文介绍了在Simulator中运行时的条件编译,而不是在设备上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否有一个编译器指令可用于在定位模拟器而不是我的设备时编译不同的代码行。类似于:

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

直接链接到文档。

推荐答案

#if TARGET_IPHONE_SIMULATOR
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
#else
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
#endif

这篇关于在Simulator中运行时的条件编译,而不是在设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆