千家信息网

Xcode 利用宏定义区分iphone 模拟器和真机

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,示例:如果在模拟器中运行就定义宏不编译rdp功能模块到app中,如果真机运行就编译rdp功能模块到app中。#if TARGET_IPHONE_SIMULATOR#define WITH_FREE_R
千家信息网最后更新 2026年11月02日Xcode 利用宏定义区分iphone 模拟器和真机

示例:

  如果在模拟器中运行就定义宏不编译rdp功能模块到app中,如果真机运行就编译rdp功能模块到app中。

  1. #if TARGET_IPHONE_SIMULATOR
  2. #define WITH_FREE_RDP NOT_BUILD_IN // 模拟器不支持RDP
  3. #elif TARGET_OS_IPHONE
  4. #define WITH_FREE_RDP BUILD_IN // 支持RDP
  5. #endif

更多更详细的信息参看TargetConditionals.h

  1. /*
  2. * Copyright (c) 2000-2008 by Apple Inc.. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. /*
  24. File: TargetConditionals.h
  25. Contains: Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone
  26. Note: TargetConditionals.h in 3.4 Universal Interfaces works
  27. with all compilers. This header only recognizes compilers
  28. known to run on Mac OS X.
  29. */
  30. #ifndef __TARGETCONDITIONALS__
  31. #define __TARGETCONDITIONALS__
  32. /****************************************************************************************************
  33. TARGET_CPU_*
  34. These conditionals specify which microprocessor instruction set is being
  35. generated. At most one of these is true, the rest are false.
  36. TARGET_CPU_PPC - Compiler is generating PowerPC instructions for 32-bit mode
  37. TARGET_CPU_PPC64 - Compiler is generating PowerPC instructions for 64-bit mode
  38. TARGET_CPU_68K - Compiler is generating 680x0 instructions
  39. TARGET_CPU_X86 - Compiler is generating x86 instructions
  40. TARGET_CPU_ARM - Compiler is generating ARM instructions
  41. TARGET_CPU_MIPS - Compiler is generating MIPS instructions
  42. TARGET_CPU_SPARC - Compiler is generating Sparc instructions
  43. TARGET_CPU_ALPHA - Compiler is generating Dec Alpha instructions
  44. TARGET_OS_*
  45. These conditionals specify in which Operating System the generated code will
  46. run. The MAC/WIN32/UNIX conditionals are mutually exclusive. The EMBEDDED/IPHONE
  47. conditionals are variants of TARGET_OS_MAC.
  48. TARGET_OS_MAC - Generate code will run under Mac OS
  49. TARGET_OS_WIN32 - Generate code will run under 32-bit Windows
  50. TARGET_OS_UNIX - Generate code will run under some non Mac OS X unix
  51. TARGET_OS_EMBEDDED - Generate code will run under an embedded OS variant
  52. of TARGET_OS_MAC
  53. TARGET_OS_IPHONE - Generate code will run under iPhone OS which
  54. is a variant of TARGET_OS_MAC.
  55. TARGET_RT_*
  56. These conditionals specify in which runtime the generated code will
  57. run. This is needed when the OS and CPU support more than one runtime
  58. (e.g. Mac OS X supports CFM and mach-o).
  59. TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers
  60. TARGET_RT_BIG_ENDIAN - Generated code uses big endian format for integers
  61. TARGET_RT_64_BIT - Generated code uses 64-bit pointers
  62. TARGET_RT_MAC_CFM - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used
  63. TARGET_RT_MAC_MACHO - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used
  64. TARGET_IPHONE_SIMULATOR - Generate code for running under iPhone Simulator
  65. ****************************************************************************************************/
  66. /*
  67. * gcc based compiler used on Mac OS X
  68. */
  69. #if defined(__GNUC__) && ( defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__) )
  70. #define TARGET_OS_MAC 1
  71. #define TARGET_OS_WIN32 0
  72. #define TARGET_OS_UNIX 0
  73. #define TARGET_OS_EMBEDDED 0
  74. #define TARGET_OS_IPHONE 1
  75. #define TARGET_IPHONE_SIMULATOR 1
  76. #if defined(__ppc__)
  77. #define TARGET_CPU_PPC 1
  78. #define TARGET_CPU_PPC64 0
  79. #define TARGET_CPU_68K 0
  80. #define TARGET_CPU_X86 0
  81. #define TARGET_CPU_X86_64 0
  82. #define TARGET_CPU_ARM 0
  83. #define TARGET_CPU_MIPS 0
  84. #define TARGET_CPU_SPARC 0
  85. #define TARGET_CPU_ALPHA 0
  86. #define TARGET_RT_LITTLE_ENDIAN 0
  87. #define TARGET_RT_BIG_ENDIAN 1
  88. #define TARGET_RT_64_BIT 0
  89. #ifdef __MACOS_CLASSIC__
  90. #define TARGET_RT_MAC_CFM 1
  91. #define TARGET_RT_MAC_MACHO 0
  92. #else
  93. #define TARGET_RT_MAC_CFM 0
  94. #define TARGET_RT_MAC_MACHO 1
  95. #endif
  96. #elif defined(__ppc64__)
  97. #define TARGET_CPU_PPC 0
  98. #define TARGET_CPU_PPC64 1
  99. #define TARGET_CPU_68K 0
  100. #define TARGET_CPU_X86 0
  101. #define TARGET_CPU_X86_64 0
  102. #define TARGET_CPU_ARM 0
  103. #define TARGET_CPU_MIPS 0
  104. #define TARGET_CPU_SPARC 0
  105. #define TARGET_CPU_ALPHA 0
  106. #define TARGET_RT_LITTLE_ENDIAN 0
  107. #define TARGET_RT_BIG_ENDIAN 1
  108. #define TARGET_RT_64_BIT 1
  109. #define TARGET_RT_MAC_CFM 0
  110. #define TARGET_RT_MAC_MACHO 1
  111. #elif defined(__i386__)
  112. #define TARGET_CPU_PPC 0
  113. #define TARGET_CPU_PPC64 0
  114. #define TARGET_CPU_68K 0
  115. #define TARGET_CPU_X86 1
  116. #define TARGET_CPU_X86_64 0
  117. #define TARGET_CPU_ARM 0
  118. #define TARGET_CPU_MIPS 0
  119. #define TARGET_CPU_SPARC 0
  120. #define TARGET_CPU_ALPHA 0
  121. #define TARGET_RT_MAC_CFM 0
  122. #define TARGET_RT_MAC_MACHO 1
  123. #define TARGET_RT_LITTLE_ENDIAN 1
  124. #define TARGET_RT_BIG_ENDIAN 0
  125. #define TARGET_RT_64_BIT 0
  126. #elif defined(__x86_64__)
  127. #define TARGET_CPU_PPC 0
  128. #define TARGET_CPU_PPC64 0
  129. #define TARGET_CPU_68K 0
  130. #define TARGET_CPU_X86 0
  131. #define TARGET_CPU_X86_64 1
  132. #define TARGET_CPU_ARM 0
  133. #define TARGET_CPU_MIPS 0
  134. #define TARGET_CPU_SPARC 0
  135. #define TARGET_CPU_ALPHA 0
  136. #define TARGET_RT_MAC_CFM 0
  137. #define TARGET_RT_MAC_MACHO 1
  138. #define TARGET_RT_LITTLE_ENDIAN 1
  139. #define TARGET_RT_BIG_ENDIAN 0
  140. #define TARGET_RT_64_BIT 1
  141. #elif defined(__arm__)
  142. #define TARGET_CPU_PPC 0
  143. #define TARGET_CPU_PPC64 0
  144. #define TARGET_CPU_68K 0
  145. #define TARGET_CPU_X86 0
  146. #define TARGET_CPU_X86_64 0
  147. #define TARGET_CPU_ARM 1
  148. #define TARGET_CPU_MIPS 0
  149. #define TARGET_CPU_SPARC 0
  150. #define TARGET_CPU_ALPHA 0
  151. #define TARGET_RT_MAC_CFM 0
  152. #define TARGET_RT_MAC_MACHO 1
  153. #define TARGET_RT_LITTLE_ENDIAN 1
  154. #define TARGET_RT_BIG_ENDIAN 0
  155. #define TARGET_RT_64_BIT 0
  156. #else
  157. #error unrecognized GNU C compiler
  158. #endif
  159. /*
  160. * CodeWarrior compiler from Metrowerks/Motorola
  161. */
  162. #elif defined(__MWERKS__)
  163. #define TARGET_OS_MAC 1
  164. #define TARGET_OS_WIN32 0
  165. #define TARGET_OS_UNIX 0
  166. #define TARGET_OS_EMBEDDED 0
  167. #if defined(__POWERPC__)
  168. #define TARGET_CPU_PPC 1
  169. #define TARGET_CPU_PPC64 0
  170. #define TARGET_CPU_68K 0
  171. #define TARGET_CPU_X86 0
  172. #define TARGET_CPU_MIPS 0
  173. #define TARGET_CPU_SPARC 0
  174. #define TARGET_CPU_ALPHA 0
  175. #define TARGET_RT_LITTLE_ENDIAN 0
  176. #define TARGET_RT_BIG_ENDIAN 1
  177. #elif defined(__INTEL__)
  178. #define TARGET_CPU_PPC 0
  179. #define TARGET_CPU_PPC64 0
  180. #define TARGET_CPU_68K 0
  181. #define TARGET_CPU_X86 1
  182. #define TARGET_CPU_MIPS 0
  183. #define TARGET_CPU_SPARC 0
  184. #define TARGET_CPU_ALPHA 0
  185. #define TARGET_RT_LITTLE_ENDIAN 1
  186. #define TARGET_RT_BIG_ENDIAN 0
  187. #else
  188. #error unknown Metrowerks CPU type
  189. #endif
  190. #define TARGET_RT_64_BIT 0
  191. #ifdef __MACH__
  192. #define TARGET_RT_MAC_CFM 0
  193. #define TARGET_RT_MAC_MACHO 1
  194. #else
  195. #define TARGET_RT_MAC_CFM 1
  196. #define TARGET_RT_MAC_MACHO 0
  197. #endif
  198. /*
  199. * unknown compiler
  200. */
  201. #else
  202. #if defined(TARGET_CPU_PPC) && TARGET_CPU_PPC
  203. #define TARGET_CPU_PPC64 0
  204. #define TARGET_CPU_68K 0
  205. #define TARGET_CPU_X86 0
  206. #define TARGET_CPU_X86_64 0
  207. #define TARGET_CPU_ARM 0
  208. #define TARGET_CPU_MIPS 0
  209. #define TARGET_CPU_SPARC 0
  210. #define TARGET_CPU_ALPHA 0
  211. #elif defined(TARGET_CPU_PPC64) && TARGET_CPU_PPC64
  212. #define TARGET_CPU_PPC 0
  213. #define TARGET_CPU_68K 0
  214. #define TARGET_CPU_X86 0
  215. #define TARGET_CPU_X86_64 0
  216. #define TARGET_CPU_ARM 0
  217. #define TARGET_CPU_MIPS 0
  218. #define TARGET_CPU_SPARC 0
  219. #define TARGET_CPU_ALPHA 0
  220. #elif defined(TARGET_CPU_X86) && TARGET_CPU_X86
  221. #define TARGET_CPU_PPC 0
  222. #define TARGET_CPU_PPC64 0
  223. #define TARGET_CPU_X86_64 0
  224. #define TARGET_CPU_68K 0
  225. #define TARGET_CPU_ARM 0
  226. #define TARGET_CPU_MIPS 0
  227. #define TARGET_CPU_SPARC 0
  228. #define TARGET_CPU_ALPHA 0
  229. #elif defined(TARGET_CPU_X86_64) && TARGET_CPU_X86_64
  230. #define TARGET_CPU_PPC 0
  231. #define TARGET_CPU_PPC64 0
  232. #define TARGET_CPU_X86 0
  233. #define TARGET_CPU_68K 0
  234. #define TARGET_CPU_ARM 0
  235. #define TARGET_CPU_MIPS 0
  236. #define TARGET_CPU_SPARC 0
  237. #define TARGET_CPU_ALPHA 0
  238. #elif defined(TARGET_CPU_ARM) && TARGET_CPU_ARM
  239. #define TARGET_CPU_PPC 0
  240. #define TARGET_CPU_PPC64 0
  241. #define TARGET_CPU_X86 0
  242. #define TARGET_CPU_X86_64 0
  243. #define TARGET_CPU_68K 0
  244. #define TARGET_CPU_MIPS 0
  245. #define TARGET_CPU_SPARC 0
  246. #define TARGET_CPU_ALPHA 0
  247. #else
  248. /*
  249. NOTE: If your compiler errors out here then support for your compiler
  250. has not yet been added to TargetConditionals.h.
  251. TargetConditionals.h is designed to be plug-and-play. It auto detects
  252. which compiler is being run and configures the TARGET_ conditionals
  253. appropriately.
  254. The short term work around is to set the TARGET_CPU_ and TARGET_OS_
  255. on the command line to the compiler (e.g. -DTARGET_CPU_MIPS=1 -DTARGET_OS_UNIX=1)
  256. The long term solution is to add a new case to this file which
  257. auto detects your compiler and sets up the TARGET_ conditionals.
  258. Then submit the changes to Apple Computer.
  259. */
  260. #error TargetConditionals.h: unknown compiler (see comment above)
  261. #define TARGET_CPU_PPC 0
  262. #define TARGET_CPU_68K 0
  263. #define TARGET_CPU_X86 0
  264. #define TARGET_CPU_ARM 0
  265. #define TARGET_CPU_MIPS 0
  266. #define TARGET_CPU_SPARC 0
  267. #define TARGET_CPU_ALPHA 0
  268. #endif
  269. #define TARGET_OS_MAC 1
  270. #define TARGET_OS_WIN32 0
  271. #define TARGET_OS_UNIX 0
  272. #define TARGET_OS_EMBEDDED 0
  273. #if TARGET_CPU_PPC || TARGET_CPU_PPC64
  274. #define TARGET_RT_BIG_ENDIAN 1
  275. #define TARGET_RT_LITTLE_ENDIAN 0
  276. #else
  277. #define TARGET_RT_BIG_ENDIAN 0
  278. #define TARGET_RT_LITTLE_ENDIAN 1
  279. #endif
  280. #if TARGET_CPU_PPC64 || TARGET_CPU_X86_64
  281. #define TARGET_RT_64_BIT 1
  282. #else
  283. #define TARGET_RT_64_BIT 0
  284. #endif
  285. #ifdef __MACH__
  286. #define TARGET_RT_MAC_MACHO 1
  287. #define TARGET_RT_MAC_CFM 0
  288. #else
  289. #define TARGET_RT_MAC_MACHO 0
  290. #define TARGET_RT_MAC_CFM 1
  291. #endif
  292. #endif
  293. #endif /* __TARGETCONDITIONALS__ */
模拟器 功能 功能模块 模块 e.g. 支持 编译 运行 信息 更多 示例 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广州大一互联网络科技有限公司 互联网科技公司税收优惠 奇酷互联网科技 中国互联网科技发展 凡科互联网科技 云电互联网科技 天扬科技互联网广告 互联网科技创新企业排名 宁夏科技产业互联网案例 移动互联网年度科技创新 健康食品互联网创新科技园项目 互联网在线教育科技创业 广州百诚互联网科技有限公司官网 上海互联网科技公司ppt 陕西云淼互联网科技公司 南京一网一红互联网科技有限公司 全球科技与互联网公司市值变化 互联网科技机房 盐城市攀科互联网科技有限公司 北京品多多互联网科技有限公司 南京欣网互联网络科技有限公司 蓝思科技飞鸽互联网 剑昆互联网络科技有限公司临桂 北京华百购互联网科技有限公司 岳阳华臻互联网科技有限公司 互联网金融科技公司的优势 互联网与数字科技关系 易企秀互联网科技是做什么的 互联网科技手机排行榜 重庆科技产业互联网有哪些
0