github:https://github.com/CocoaPods/CocoaPods
官方网站:http://www.cocoapods.org/
1、安装 RubyGems
RubyGems 官方网站:http://rubygems.org/
RubyGems 下载地址:http://rubygems.org/pages/download
下载成功后,解压缩
打开终端,cd 打开
执行命令:
sudo ruby setup.rb
2、安装 CocoaPods
终端,执行命令:
sudo gem install cocoapods
报错:
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/xcodeproj-0.5.2 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/xcodeproj-0.5.2/ext/xcodeproj/gem_make.ou
解决方案:
参考:https://github.com/CocoaPods/cocoapods.org/issues/19
打开XCode,Preferences -> Downloads -> Components,下载 Command Line Tools
Command Line Tools 下载成功后,重新安装,成功!
终端执行命令:
pod setup
等了很久很久……
设置成功!
3、编写 Podfile
在项目根目录下,新建文本文件,文件名为:Podfile
查询库,终端执行命令:
pon search [QUERY]
Searches for pods, ignoring case, whose name matches `QUERY'. If the
`--full' option is specified, this will also search in the summary and
description of the pods.
编写 Podfile,以安装ASIHTTPRequest为例,内容如下:
platform :ios
pod 'ASIHTTPRequest'
4、安装库
编写完 Podfile 文件之后,终端执行:
pod install
等了很久很久……
以项目PodSample为例,安装成功的目录,大概是这个样子的:
注意:以后呢,打开项目,打开这个.xcworkspace文件,而不是.xcodeproj文件了!
5、使用
以 ASIHTTPRequest 为例,仅仅需要 #import <ASIHTTPRequest/ASIHTTPRequest.h>
太方便了!!!
请发表评论