第一次使用
1:查询镜像目录
$gem sources -l
查询结果:
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
(第一次加载是https://rubygems.org/
)这个路径加载慢,要换成国内的
切换方法:https://ruby.taobao.org
2 安装cocoapods
(1)安装
$ gem install cocoapods
OS X 10.11以后,在终端输入以下命令:
sudo gem install -n /usr/local/bin cocoapods
返回结果
Fetching: cocoapods-1.4.0.gem (100%)
Successfully installed cocoapods-1.4.0
Parsing documentation for cocoapods-1.4.0
Installing ri documentation for cocoapods-1.4.0
Done installing documentation for cocoapods after 4 seconds
1 gem installed
(2)更新:$sudo gem update --system
输入密码后(输入密码显示是空白的,不用管)
返回结果:RubyGems system software updated
配置
如果已经安装了,直接使用下边步骤
1 $cd 项目路径
(如果不知道路径,可以选中工程目录然后拖拽到命令行)
2 创建podfile文件 $touch podfile
3 查询要接入的第三方库,比如:AFNetworking
$ pod search AFNetworking
提示:Creating search index for spec repo 'master'..
,然后慢慢等吧,时间不固定,至少5分钟吧。(是在写东西,)
提示:
-> AFNetworking (3.1.0)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 3.1.0'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
- Subspecs:
- AFNetworking/Serialization (3.1.0)
- AFNetworking/Security (3.1.0)
- AFNetworking/Reachability (3.1.0)
- AFNetworking/NSURLSession (3.1.0)
- AFNetworking/UIKit (3.1.0)
- 后边还有一大串,太长了没有复制
3 编辑podfile文件
(1):$vim podfile
(2) 打开文件后输入(敲键盘"i",是输入)
platform :ios, '8.0'
target 'TargetName' do
pod 'AFNetworking', '~> 3.1.0'
end
platform :ios, ‘8.0’ :要求使用8.0以上
target ‘TargetName’ do :TargetName 改成项目名字
pod ‘AFNetworking’, ‘~> 3.1.0’ :AFNetworking 是3.1.0 版本,也可以改成’~> AFNetworking’,意思是最新版本;
退出编辑:先按左上角的esc键,再按":"键,再输入wq,点击回车,就保存并退出。
4 安装更新(没有安装过的SDK)
pod install --verbose --no-repo-update
pod update podName
CocoaPods会去找到指定podName的更新
当提示:Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
就成功了;
提示:[!] Please close any current Xcode sessions and use
*****.xcworkspacefor this project from now on.
这里说的是使用.xcworkspace 打开项目,不能使用之前的那个打开了。