默认是放到主target
- platform :ios, '8.0'
多个target使用1
pod 'AFNetworking'
end
多个target的话,简单一点可以一个一个指定,这样可以做到精确控制,但是有很多重复代码
- platform :ios, '8.0'
多个target使用1
target 'Target' do
pod 'AFNetworking'
end
target 'Target1' do
pod 'AFNetworking'
end
或者这样写,使用ruby函数定义,这样比上一个方法要清晰,公共的一个,不同的一个
platform :ios, '8.0'
多个target使用2
def CommonPod
pod 'AFNetworking'
end
def PodTest1
pod 'SDWebImage'
end
target 'Target2' do
CommonPod
end
target 'Target1' do
CommonPod
PodTest1
end
image我们都知道,Xcode新建的一个project,可以包含对个target,默认包含了一个与project同名的target,有时候我们可能会在原来的基础上添加多个target(如下图),但是我们却发现在新增加的target的控制器文件下导入不了pods下的第三方库
现在在新建的target下导入SVProgressHUD,就显示报错了
image原因很简单,因为我们的Profile中只针对LXFPorject这个target设置了依赖库
image想要让它支持LXFOtherProj这个新添加的target,最简单粗暴的方式如下
image这个地方修改完后需要我们再 【pod install】一下,再次编译,成功了
但是如果以后引入的第三方越来越多呢?这样搞岂不是麻烦得很~~那有没有什么简单的方式呢?
image其实Profile中使用的是Ruby语法,它也支持数组,遍历这些,所以我们可以用Ruby来循环让它对各个的target设置依赖库
这样就可以了,最后别忘了 pod install
以后想让它为其它target设置依赖库,可以直接将target的名字添加到targetArray中
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
workspace 'FTRK-OIL.xcworkspace'
inhibit_all_warnings!
pod 'AFNetworking', '~> 3.1.0'
pod 'IQKeyboardManager', '~> 5.0.6'
pod 'JSONModel', '~> 1.7.0'
pod 'Masonry'
pod 'MJExtension', '~> 3.0.13'
pod 'MJRefresh', '~> 3.1.14.1'
pod 'SDWebImage', '~> 4.1.2'
pod 'Bugly'
pod 'XHLaunchAd', '~> 3.9.7'
pod 'FLAnimatedImage'
pod 'WechatOpenSDK', '~> 1.8.3'
pod 'UMCAnalytics', '~> 5.5.2'
pod 'UMCCommon', '~> 1.5.3'
pod 'TYAttributedLabel', '~> 2.6.2'
ftrkTargets = ['FTRK-OIL', 'FTRK-OIL-DEMO','FTRK-OIL-TEST','FTRK-OIL-TEST-PUB','FTRK-OIL-DEMO-PUB']
ftrkTargets.each do |t|
target t do
project 'FTRK-OIL.xcodeproj'
end
end
注意 如果pod install报错如:[!] Unable to find the Xcode project
/Users/hujason/Documents/ios/IosWalk/path/to/.xcodeproj
for the targetPods
.
注意 ***.xcodeproj这里的名字或者路径无法匹配,修改更正一下就好了。
网友评论