cocoaPods官方主页:https://cocoapods.org/
GitHub下载地址:https://github.com/CocoaPods/CocoaPods-app
第一次安装cocoaPods,并导入三方库,主要资源也是网上的集成,后续的还有待使用再续。
1、Ruby环境搭建(更新)
查看:打开Mac终端,
终端输入:$ruby -v,查看当前是否安装Ruby等。
成功安装:ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14](一般Mac都是默认安装的)
更新:
终端输入:gem sources –remove https://rubygems.org/
终端输入:$gem sources -a https://ruby.taobao.org/
终端输入:$gem sources -l (用来检查使用替换镜像位置成功)
2、安装cocoaPods
终端输入:$sudo gem install cocoapods (安装正式版本)
/*显示成功安装(工程路径)
apple-mini:PodTest tg$ sudo gem install cocoapods --pre
Password:
Fetching: cocoapods-core-1.0.0.beta.4.gem (100%)
Successfully installed cocoapods-core-1.0.0.beta.4
.........
12 gems installed
*/
/*显示成功安装(cd 到根路径)
apple-mini:~ tg$ sudo gem install cocoapods --pre
Successfully installed cocoapods-1.0.0.beta.4
Parsing documentation for cocoapods-1.0.0.beta.4
1 gem installed
*/
3、更新缓存(应该是这个意思)
终端输入:$pod repo remove master
/*显示成功
apple-mini:~ tg$ pod repo remove master
Removing spec repo `master`
*/
终端输入:$pod setup
/*显示成功
apple-mini:PodTest tg$ pod setup
Setting up CocoaPods master repo
CocoaPods 1.0.0.beta.4 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Setup completed
*/
4、加入GitHub上的三方库到工程(假设新建名为‘PodTest’的工程)
终端输入:$pod search AFNetworking
/*搜索到GitHub中关键字为AFNetworking(带版本号的)的项目
-> AFNetworking (3.0.4)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 3.0.4'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 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.0.4)
- AFNetworking/Security (3.0.4)
- AFNetworking/Reachability (3.0.4)
- AFNetworking/NSURLSession (3.0.4)
- AFNetworking/UIKit (3.0.4)
<Esc - : - q - Enter>-- 'q'退出
*/
终端输入:$cd /Users/tg/Desktop/weixin9_16/Test/PodTest (工程路径)
终端输入:$vim Podfile
/*创建、编辑Podfile(一定是这个名字的编译文件,用于导入第三方库)
单击‘i’开始编辑
platform:ios, '8.0'
use_frameworks!
target 'PodTest' do
pod 'AFNetworking', '~>3.0.4'
end
以上是官方导入文件标准,其中系统版本号在加入的第三方有限制时一定要写上(没限制的可不写),<Esc - : - wq - Enter>英文输入法下四步退出编辑界面(表示保存并退出)。
*/
终端输入:$pod install
/*成功下载、导入AFNetworking 3.0.4(第三方库)
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.0.4)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `PodTest.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total
pod installed.
生成Podfile.lock文件后,下次导入其它三方库,可在终端输入:$pod update更新编辑的Podfile文件,改变Podfile.lock文件。
*/
终端输入:$open PodTest.xcworkspace(终端打开工程,也可手动打开.xcworkspace后缀的工程文件)
以上是初步接触cocoaPods的过程,错误的百度一下就能有答案解决,就不赘述了,也可以参考官网的安装过程guides可以避免一般错误。