安装cocoapods

来源:互联网 发布:birch算法 编辑:程序博客网 时间:2024/06/06 02:02

第一部分:

**注意:$这个符号不要写入,仅至在此表示区分**

CocoaPods 的安装
步骤1 - 安装 RVM
RVM 是干什么的这里就不解释了,后面你将会慢慢搞明白。
$ curl -L https://get.rvm.io | bash -s stable
期间可能会问你sudo管理员密码,以及自动通过homebrew安装依赖包,等待一段时间后就可以成功安装好 RVM。

然后,载入 RVM 环境
$ source ~/.rvm/scripts/rvm
很快,不显示任何变化

检查一下是否安装正确
$ rvm -v
rvm 1.26.11 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]
步骤2 - 用 RVM 安装 Ruby 环境

$ rvm install 2.0.0
同样继续等待漫长的下载,编译过程,完成以后,Ruby, Ruby Gems 就安装好了。

等待的开始:Installing requirements for osx. Updating system….

漫长

Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl……
安装需要的软件包:autoconf的,automake的,libtool的,pkg配置,libyaml,readline的,libksba,OpenSSL的

漫长……
步骤3 - 设置 Ruby 版本
RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本
rvm2.0.0defaultrvminstall ruby -v
ruby 2.0.0p643 (2015-02-25 revision 49749) [x86_64-darwin14.1.0]

$ gem -v
2.4.6
步骤4 - 安装 CocoaPods
如果你在天朝,在终端中敲入这个命令之后,会发现半天没有任何反应。原因无他,因为那堵墙阻挡了cocoapods.org
所以要更换一下镜像,用淘宝的镜像;
注意:以前的 http://ruby.taobao.org/已经失效,需要在 http 后加上 s
移除原始镜像
$ gem source -r https://rubygems.org/
安装淘宝镜像
$ gem source -a https://ruby.taobao.org
为了验证你的Ruby镜像是并且仅是taobao,可以用以下命令查看:
$ gem sources
只有在终端中出现下面文字才表明你上面的命令是成功的:
* CURRENT SOURCES *
https://ruby.taobao.org/

然后输入以下命令进行安装 CocoaPods
$ sudo gem install cocoapods

---到这里 CocoaPods 就安装完成了---

第二部分:
CocoaPods 的使用

场景1:利用 CocoaPods, 在项目中导入第三方类库;
以导入 AFNetWorking 为例;
AFNetworking类库在GitHub地址是:
https://github.com/AFNetworking/AFNetworking

pod “AFNetworking”, “~> 2.0”

先创建工程
在工程的更目录下创建 Podfile 空白文件 (也就是跟*.xcodeproj文件在同一个文件夹)

1.用命令行:touch Podfile 便可以创建pod文件

2.在终端再输入 vim Podfile 输入 i 开始导入所需要的框架 在 vim 中输入以下内容: platform :ios,
‘7.0’ pod “AFNetworking”, “~> 2.0”

升级后的输入形式

platform :ios, ‘8.0’
use_frameworks!
target ‘TestTableCell’ do #你的项目Targets
pod ‘ZXPAutoLayout’, ‘2.0.1’
end

3.完成以后输入: wq 保存并退出,(如果左下角显示 INSIRD, 则需要先按 ESC 在输入命令)

  1. 再输入pod install 便可等待自动导入

cocoa pods命令:
Commands:

+ cache      Manipulate the CocoaPods cache(操纵的CocoaPods缓存)+ init       Generate a Podfile for the current directory.(产生Podfile当前目录。)+ install    Install project dependencies to Podfile.lock versions(安装项目的依赖Podfile.lock版本)+ ipc        Inter-process communication(进程间通信)+ lib        Develop pods+ list       List pods+ outdated   Show outdated project dependencies(显示过时的项目依赖)+ plugins    Show available CocoaPods plugins+ repo       Manage spec-repositories+ search     Search for pods.+ setup      Setup the CocoaPods environment+ spec       Manage pod specs+ trunk      Interact with the CocoaPods API (e.g. publishing new specs)+ try        Try a Pod!+ update     Update outdated project dependencies and create new             Podfile.lock

Options:

--silent     Show nothing--version    Show the version of the tool--verbose    Show more debugging information--no-ansi    Show output without ANSI codes--help       Show help banner of specified command
0 0
原创粉丝点击