CocoaPods的安装与使用

2019-05-06  本文已影响0人  当优秀成为习惯

(1)安装ruby源

sudo gem update --system

gem source -l

gem sources --remove https://rubygems.org/(链接换成你实际的源)

gem sources -a https://gems.ruby-china.com

sudo gem install -n /usr/local/bin cocoapods

(2)安装cocoapods

sudo gem install cocoapods

整个pod的安装过程就这样简单,安装成功查看cocoapods版本

pod --version
目前最新的是1.6.1

(3)cocoapods使用

cd 项目路径

pod init

执行完操作在项目中会出现Podfile文件,这个文件就是管理我们的第三方库的

方法1:手动在项目工程Podfile添加(推荐使用)

platform :ios,‘8.0’
target‘你的项目名称’do
pod‘AFNetworking’,‘~> 3.0.4’(如果不指定版本号,可以省略,‘~> 3.0.4’,系统会默认安装最新的版本)
end

方法2:在终端用命令行添加

vim Podfile
会弹出podfile文件,这时在里边输入:
platform :ios,‘8.0’
target‘你的项目名称’do
pod‘AFNetworking’,‘~> 3.0.4’
end
写完之后继续敲:wq来退出podfile文件

pod install

如果后续还需要增删改查第三方库

pod update

⚠️执行update操作系有时提示失败:
错误如下:

[!] CocoaPods was not able to update the master repo. If this is an unexpected issue and persists you can inspect it running pod repo update --verbose

那就根据提示执行命令

pod repo update --verbose

参考文章:https://www.jianshu.com/p/265d8e4dd73a

关于pod install 和 pod update

参考文章:https://zedxpp.com/2018/07/23/正确的使用pod%20install%20和%20pod%20update%20-%20CocoaPods/

上一篇 下一篇

猜你喜欢

热点阅读