maybe-liu

简介

介绍一些CocoaPods一些特别的用法

CocoaPods github地址

CocoaPods 官方地址

1. 指定第三方库版本

1. 固定版本

target 'MyApp' do use_frameworks! pod 'AFNetworking','3.2.0' end
这是将AFNetworking 完全限定在 3.2.0版本,不会更新

2.小版本浮动
target 'MyApp' do
 use_frameworks!  
 pod 'AFNetworking','~> 3.2.0'
end

这样设置 AFNetworking 会在 3.2.0 ~ 3.9.9 之间版本浮动,不包含4.0.0(这里就是泛指,不必较真,不要提AFNetworking 没有3.9.9)

3.完全不限制版本
target 'MyApp' do
  use_frameworks!  
  pod 'AFNetworking',
end

这样设置 AFNetworking 不限制版本,任何版本都可以,不过下载的版本下来肯定是最新的。

提示

在项目中,我建议使用方法一,也就是固定版本。特别是在多人开发的项目中

在项目中,可能会遇到更新pod。如果不指定版本的花,就会出现每个人第三方库版本不一样

如果是需要更新第三方库,直接修改版本号,更新pod即可。

尽量小组内做到协调统一

4.官方解释版本

1522107151301.jpg

'> 0.1'      大于0.1版本
'>= 0.1'     大于等于0.1版本
'< 0.1'      小于0.1版本
'<= 0.1'     小于等于0.1版本
'~> 0.1.2'   大于0.1.2 小于0.2,不含0.2
'~> 0.1'     0.1以上 1.0以下,不含0.1
'~> 0'       0和以上,等于没有此约束

CocoaPods 支持私有Spec仓库,我们可以建立自己的源,也可以使用非官方的源,只要符合规定的都可以指定

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'
使用git的HEAD指向的分支
target 'MyApp' do
  use_frameworks!  
  pod 'AFNetworking',:head
end
使用master分支
target 'MyApp' do
  use_frameworks!  
  pod 'LBXScan',git:'https://github.com/MxABC/LBXScan.git'
end
指定branch
target 'MyApp' do
 use_frameworks!  
 pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'
end
指定tag
target 'MyApp' do
 use_frameworks!  
 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '3.2.0'
end
指定commit
target 'MyApp' do
 use_frameworks!  
 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => 'e976d63'
end
使用子库
target 'MyApp' do
  use_frameworks!  
 pod 'QueryKit/Attribute'
end
使用多个子库
target 'MyApp' do
 use_frameworks!  
 pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
end
使用本地库

通过:path 可以指定本地代码,不过需要确保目录中包含 podspec 文件。

target 'MyApp' do
 use_frameworks!  
 pod 'AFNetworking', :path => '~/Documents/AFNetworking'
end
指定target的依赖库
target 'MyApp' do
 use_frameworks!  
 pod 'SDWebImage', '4.0'
    target 'otherTaget' do
     use_frameworks!
     pod 'AFNetworking','3.2.0'
    end
 
end
排除target
target 'MyApp' :exclusive => true do
  use_frameworks!  
  pod 'AFNetworking','3.2.0'
end
指定xocdeproj

默认会使用 podfile 文件同级目录下第一个xcodeproj ,但也是可以指定的

 xcodeproj 'testProject'
 target:test do
   use_frameworks!  
   pod 'AFNetworking','3.2.0'
   xcodeproj 'otherProject'   
  end 
指定连接的target

如果不显式指定连接的target,Pods会默认连接project的第一个target。如果需要,可以使用link_with指定连接一个活多个target

target link_with 'MyApp','otherApp' do
  use_frameworks!  
  pod 'AFNetworking','3.2.0'
 end
指定依赖库的配置文件
pod 'PonyDebugger', :configuration => ['Release']
指定target的配置文件
xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug
使用Dynamic Frameworks代替Static Libraries

通过标志use_frameworks!就可知开启这个功能。如果需要使用Swift的库,就必须加上这个标志了。

抑制警告

inhibit_warnings参数能够有效的抑制CocoaPods引入的第三方代码库产生的warning

target 'MyApp' do pod 'AFNetworking','3.2.0',:inhibit_warnings => true end

全局抑制警告
 platform :ios, '8.0'
 inhibit_all_warnings!
 target 'MyApp' do
  pod 'AFNetworking','3.2.0'
 end

相关文章: