Cocoapods梳理
在项目中每次使用Cocoapods的时候都仅仅是库的更新删除等,很少会用到环境更新等,故梳理一份,防止长久没用到,自己会忘记里面的细节。
Cocoapods 是什么?
Cocoapods 是iOS开发中,第三方库的管理工具;我们可以通过Cocoapods来为自己的项目pod进第三方库,不用手动添加这些库的依赖;同时我们可以通过Cocoapods来管理pod进来的第三方库的版本。
Cocoapods怎么用?
统一使用终端输入一下命令
1-升级Ruby环境
gem update --system

2- 若无权限,输入
sudo gem update --system

看到🔑的符号,输入密码,但此时光标是不会出现的;输入完成后,按回车键。获取到权限后,终端就会执行更新。

命令行出现 RubyGems system software updated 代表已经更新成功。
3- 查看当前镜像
gem sources -l
就会看到

4- 更换Ruby镜像
- 先移除现有镜像
gem sources --remove https://rubygems.org/
- 再添加国内最新镜像
gem sources -a https://gems.ruby-china.org/
- 最后再输入
gem sources -l
查看当前的镜像

5- 安装cocoapods:
sudo gem install cocoapods
会出现🔑,输入密码回车即可;回车后,会发现提示没有权限。

6- 无权限,则输入
sudo gem install -n /usr/local/bin cocoapods

如果之前已经install过一次,第二次就会很快了:

至此Cocoapods安装成功。
7- 执行
pod setup

这条命令是将Github上的开源库都托管都安装Podspec索引安装到到本地,所以需要的时间相对比较长,要耐心等。

恭喜setup成功了。
8- 搜索第三方库
pod search AFNetworking

出现图中那句话,说明查询成功了;然后输入q
即可退出查询;
9- 创建Podfile文件
touch Podfile 或者 pod init

10- 编辑Podfile文件
- 开始编辑
vim Podfile
- 按
i
即可开始编辑,可插入需要第三方库

11- 保存并退出编辑
- 先点击
esc按键
- 再输入
:wq
,然后回车即可
wqvim.png
12- 将第三方库pod到项目中
pod install
pod update
如果发现执行pod install或者pod update都卡在了Analyzing dependencies不动,就可以使用一下两种方式,速度会快很多。
当执行以上两个命令的时候会升级CocoaPods的spec仓库,加如—verbose —no-repo-update
,所以速度就会提升不少。
po install —verbose —no-repo-update
pod update —verbose —no-repo-update

pod完成后,在工程文件中就会出现.xcworkspace
文件;之后就使用.xcworkspace
文件打开工程,可以看到pod进的第三方库了。不用.xcodeproj
文件打开工程了;
就这样,就可以了!!!
网友评论