代码之家  ›  专栏  ›  技术社区  ›  arachide

编译项目时是否可以检测目标

  •  0
  • arachide  · 技术社区  · 7 年前

    我有一个有两个目标的应用程序,lite版本/目标中有google admob广告。 现在我使用下面的代码进行处理。

    //App_Prefix.pch
    #define _lite
    

    在appDelegate中

    // AppDelegate.m
    #ifdef _lite
    
    @import GoogleMobileAds;
    #endif
    @implementation  AppDelegate
    

    编译项目时是否可以检测目标。 下面的代码可以检测目标,

      //-------------detect target
      #define _lite [ [[[NSProcessInfo processInfo]environment]objectForKey:@"TARGET"] isEqualToString:@"lite"]
    

    但它不适合以前的零件

    @implementation 
    

    欢迎您的评论

    1 回复  |  直到 7 年前
        1
  •  3
  •   Bilal hao zou    7 年前

    选项1

    使用可以定义 Preprocessor Macros 针对每个目标。

    1. 转到项目设置
    2. 选择目标
    3. 在里面 Build Settings 预处理宏
    4. 添加宏,例如 APP_TARGET_A 对于所有配置(调试/发布)

      enter image description here

    5. 对所有其他目标执行相同操作

    现在,您可以使用在 .pch 文件

    #define APP_TARGET_A
    @implementation 
    #endif
    

    选项2

    你可以有不同的 .pch公司 每个目标的文件。复制 .pch公司 文件,例如 Target_A_Prefix.pch Target_B_Prefix.pch 并将其添加到项目中(取消选中所有目标)。

    内置设置转到 Prefix Header 并将路径设置为 .pch公司 对于每个配置。对所有目标执行相同的操作。

    enter image description here