iOS 多个target下合成开发
2018-10-30 本文已影响3人
墨凌风起
iOS开发过程中,经常会遇到不同版本的定制需求,或者需要iPad和iPhone版本,这样就得拷贝出多个版本,相同模块需要维护或者相同bug需要修改时就得动好几份代码,繁琐滴很!!
1.选中目标targetDemo, command+D 出现一份targetDemo copy,左侧文件列表多了一份copy-Info.plist。可修改为自己设定的target。

2.添加plist, Build Settings ->Info.plist File 修改plist文件路径

- Build Setting ->Preprocessor Macros 下添加宏定义:TARGETSTATUS。
这里targetDemo 中设置TARGETSTATUS=1;(debug 和release)
这里targetDemo01 中设置TARGETSTATUS=0(debug 和release)
4.代码
#if TARGETSTATUS ==1
//targetDemo 中需要特别定制的模块
#else
//targetDemo01 中需要特别定制的模块
#endif
5.添加资源
不同的target 可能需要的图片资源,项目名称,国际化等等都不一样。

添加资源时,add to targets选择相应的target即可。如果手快了,也可在项目中修改:

选择资源文件,在xcode右侧选中修改tagert即可。
ok,这样就可以在一份代码中实现多可版本的定制。