CocoaPods 安装与使用(IOS开发)

安装ruby

Homebrew(macOS)
macOS (High) Sierra 和 OS X El Capitan 已内置了 Ruby 2.0。

许多 macOS 用户使用 Homebrew 作为包管理器。用 Homebrew 能够非常简单地获取到最新版的 Ruby:

$ brew install ruby

这将安装最新版的 Ruby。

版本:

$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

rvm

RVM 是一个便捷的多版本 Ruby 环境的管理和切换工具.
在终端控制台命令:

$ curl -sSL https://get.rvm.io | bash -s stable

更新:

$ rvm get stable

版本:

$ rvm --version
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

gem更换源 https://gems.ruby-china.com

$ sudo gem update --system
Latest version already installed. Done.

删除已有的源,添加新的源

$ gem sources --remove https://rubygems.org/
$ gem sources --add https://gems.ruby-china.com/

查看gem源

$ gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com

版本:

$ gem --version
2.7.7

安装CocoaPods

$ sudo gem install -n /usr/local/bin cocoapods
Successfully installed cocoapods-1.8.4
Parsing documentation for cocoapods-1.8.4
Done installing documentation for cocoapods after 4 seconds
1 gem installed

安装本地库

$ pod setup

更新本地库

$ pod repo update

版本:

$ pod --version
1.8.4

使用CocoaPods

$ pod init

修改Podfile文件

platform :ios, '9.0'

target 'LumberjackDemo' do
  pod 'CocoaLumberjack'
end

安装库

$ pod install
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing CocoaLumberjack (3.6.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `LumberjackDemo.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

使用LumberjackDemo.xcworkspace打开项目。

pod install 时出现错误错误,再次执行就OK了。

$ pod install
Analyzing dependencies
[!] Couldn't determine repo type for URL: `https://cdn.cocoapods.org/`: Net::OpenTimeout

更新库

$ pod update

你可能感兴趣的:(CocoaPods 安装与使用(IOS开发))