iOS 构建多 Target 可以用来做马甲包, 具有使用性. 以下是构建新的 Target 步骤:
Step 1: 拷贝一个新的 Target.
右键选中现有的 Target, 点击 "Duplicate".
截屏 2019-11-2422.26.53.PNG
Step 2: 拷贝一个新的 Target 的名字和对应 info.plist 名字
两个都是选中, 直接 "回车键", 进行更改.
image.PNG
Step 3: 修改 Sechem 名字.
image.PNG
截屏 2019-11-2422.38.30.PNG
image.PNG
直接回车选中, 修改名字后, 点击 "Close".
Step 4: 修改 info.plist 位置.
在项目根目录下建对应的文件夹, 来存放以后不同 Target 不同的文件.
image.PNG
将现有的 info.plist 文件移到对应文件下.
image.PNG
此时要注意: 仅选择对应的文件即可.
image.PNG
Step 5: 修改 info.plist 引用.
image.PNG
image.PNG
此时要注意: 这个时候我们去编译原来的 Target 时会报错:
image.PNG
选中原有的 Target, 删除多余的引用:
image.PNG
Step 6: 添加系统的宏命令, 通过宏区分不同 Target.
image.PNG
image.PNG
使用方法: 可以在代码里直接通过 TargetType 来区分不同 Target
- if (TargetType==1) {
- NSLog(@"原来的 target");
- } else if(TargetType==2){
- NSLog(@"新建的 target");
- }
Step 7: 如果有使用 CocoaPods, 修改 Podfile 文件
- def common_Pods
- pod 'MJRefresh'
- pod 'ReactiveCocoa','~> 2.4.7'
- pod 'Masonry','~> 1.1.0'
- pod 'YYCache'
- pod 'FLEX'
- end
- target 'KnowledgeSummaryOfObjectC' do
- common_Pods
- end
- target 'TargetOne' do
- common_Pods
- end
修改 Podfile 后, 重新 pod install.
到此, 新的 Target 就已经建好, 可以使用了. 启动图片, 图标可在对应 Target 下添加.
如有问题, 欢迎留言!
来源: http://www.jianshu.com/p/7da5e58a6bdb