事实上Podfile文件可以放在任意一个目录下,需要做的是在Podfile中指定工程的路径,和原来相比,Podfile文件就在最开始的位置增加了一行,具体内容如下:
xcodeproj "/Users/wangzz/Desktop/CocoaPodsTest/CocoaPodsTest.xcodeproj"
platform :ios
pod 'Reachability', '~> 3.0.0'
pod 'SBJson', '~> 4.0.0'
platform :ios, '7.0'
pod 'AFNetworking', '~> 2.0'
指定路径使用的是xcodeproj关键字。
此后,进入Podfile文件所在路径,执行pod install命令就会和之前一样下载这些Pods依赖库,而且生成的相关文件都放在了Podfile所在目录下面,如下图:

和之前一样,我们仍然需要使用这里生成的workspace文件打开工程。
2、Podfile和target
Podfile本质上是用来描述Xcode工程中的targets用的。如果我们不显式指定Podfile对应的target,CocoaPods会创建一个名称为default的隐式target,会和我们工程中的第一个target相对应。换句话说,如果在Podfile中没有指定target,那么只有工程里的第一个target能够使用Podfile中描述的Pods依赖库。
如果想在一个Podfile中同时描述project中的多个target,根据需求的不同,可以有不同的实现方式。为了说明问题,在原来的工程中再创建一个名称为Second的target,现在的project中包含的target有:

①多个target中使用相同的Pods依赖库
比如,名称为CocoaPodsTest的target和Second的target都需要使用Reachability、SBJson、AFNetworking三个Pods依赖库,可以使用link_with关键字来实现,将Podfile写成如下方式:
link_with 'CocoaPodsTest', 'Second'
platform :ios
pod 'Reachability', '~> 3.0.0'
pod 'SBJson', '~> 4.0.0'
platform :ios, '7.0'
pod 'AFNetworking', '~> 2.0'
这种写法就实现了CocoaPodsTest和Second两个target共用相同的Pods依赖库。
②不同的target使用完全不同的Pods依赖库
CocoaPodsTest这个target使用的是Reachability、SBJson、AFNetworking三个依赖库,但Second这个target只需要使用OpenUDID这一个依赖库,这时可以使用target关键字,Podfile的描述方式如下:
target :'CocoaPodsTest' do
platform :ios
pod 'Reachability', '~> 3.0.0'
pod 'SBJson', '~> 4.0.0'
platform :ios, '7.0'
pod 'AFNetworking', '~> 2.0'
end
target :'Second' do
pod 'OpenUDID', '~> 1.0.0'
end










