7.2. 第三方开源库
CocoaPods
第三方开源库可以使用CocoaPods做iOS工程的依赖管理。每种语言发展到一个阶段,就会出现相应的依赖管理工具,例如Java语言的Maven,nodejs的npm。随着iOS开发者的增多,业界也出现了为iOS程序提供依赖管理的工具,它的名字叫做:CocoaPods。 CocoaPods项目的源码在Github上管理。该项目开始于2011年8月12日,经过多年发展,现在已经成为iOS开发事实上的依赖管理标准工具。开发iOS项目不可避免地要使用第三方开源库,CocoaPods的出现使得我们可以节省设置和更新第三方开源库的时间。
常用命令
1.先升级Gem
sudo gem update --system
2.切换cocoapods的数据源
【先删除,再添加,查看】
gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
gem sources -l
3.安装cocoapods
sudo gem install cocoapods
4.将Podspec文件托管地址从github切换到国内的oschina
【先删除,再添加,再更新】
pod repo remove master
pod repo add master http://git.oschina.net/akuandev/Specs.git
pod repo add master https://gitcafe.com/akuandev/Specs.git
pod repo update
5.设置pod仓库
pod setup
6.测试
【如果有版本号,则说明已经安装成功】
pod --version
7.利用cocoapods来安装第三方框架
01 进入要安装框架的项目的.xcodeproj同级文件夹
02 在该文件夹中新建一个文件Podfile
03 在文件中告诉cocoapods需要安装的框架信息
a.该框架支持的平台
b.适用的iOS版本
c.框架的名称
d.框架的版本
8.安装
pod install --no-repo-update
pod update --no-repo-update常用指令区别
pod install
会根据Podfile.lock文件中列举的版本号来安装第三方框架
如果一开始Podfile.lock文件不存在, 就会按照Podfile文件列举的版本号来安装第三方框架
pod update
将所有第三方框架更新到最新版本, 并且创建一个新的Podfile.lock文件
安装框架之前, 默认会执行pod repo update指令
pod install --no-repo-update
pod update --no-repo-update
安装框架之前, 不会执行pod repo update指令
Podfile.lock 文件
最后一次更新Pods时, 所有第三方框架的版本号及引用关系。
Podfile 文件
标准格式
pod install 提速
每次执行pod install和pod update的时候,cocoapods都会默认更新一次spec仓库。这是一个比较耗时的操作。在确认spec版本库不需要更新时,给这两个命令加一个参数跳过spec版本库更新,可以明显提高这两个命令的执行速度。
第三方库版本号的格式
Besides no version, or a specific one, it is also possible to use operators:
= 0.1Version 0.1.> 0.1Any version higher than 0.1.>= 0.1Version 0.1 and any higher version.< 0.1Any version lower than 0.1.<= 0.1Version 0.1 and any lower version.~> 0.1.2Version 0.1.2 and the versions up to 0.2, not including 0.2. This operator works based on the last componentthat you specify in your version requirement. The example is equal to
>= 0.1.2combined with< 0.2.0and will always match the latest known version matching your requirements.
A list of version requirements can be specified for even more fine grained control.
常用第三方库汇总
Last updated
Was this helpful?