cocoapod: 自动化管理第三方开发包的一个插件, 废话不多说, 一个新手只需做如下几个步骤

1-> 安装ruby环境(可忽略, 不是必要)

1.1 首先我们先看看当前你机器上ruby的版本

ruby -v

ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]

1.2 接下来我们来看看服务器上的ruby版本 (建议用rvm)

RVM:Ruby Version Manager, Ruby版本管理器,包括Ruby的版本管理和Gem库管理(gemset)


1.2.1 安装rvm

curl -L get.rvm.io | bash -s stable 

注意: 如果安装结尾出现, 执行下面修复命令

rvm fix-permissions

如果出现

  * To start using RVM you need to run `source /Users/vp/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.

执行下面命令, 再去安装

source ~/.rvm/scripts/rvm

1.2.2 加载文件,测试是否安装正常(按照提示操作)

source ~/.bashrc
source ~/.bash_profile
source ~/.profile
rvm -v

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

1.2.3 获取rvm列表, 就能看到最新ruby版本了, 如果与你机器的ruby版本不一致可以选择升级(⊙o⊙)哦

rvm list known

1.3 安装最新ruby(当前如果当前ruby版本够用你可以选择不安装)

rvm install 2.4

1.3.1 安装的过程需要手动按一下enter(回车)键

1.3.2 按完enter之后系统还会提示要你开机密码做验证

注意: 如果安装失败提示

Error running 'requirements_osx_port_libs_install curl-ca-bundle automake libtool libyaml libffi libksba',showing last 15 lines of /Users/acewill/.rvm/log/1468253599_ruby-2.3.0/package_install_curl-ca-bundle_automake_libtool_libyaml_libffi_libksba.log

原因是需要安装Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装完之后在跳到【1.3】

1.3.3 检查版本是否安装成功

ruby -v

2-> 更换gem源
gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找、安装、升级和卸载软件包, 所以一定确保有ruby环境才能下面的操作.
国内人员不使用git自带的,因为自带的gem源是国外的网址,taobao为我们提供了一个很不错的'gem源', 现在的taobao源团队已经维护使用ruby-china, 所以现在推荐使用ruby-china

// 移除旧的
gem sources --remove https://rubygems.org/
// 添加新的
gem sources --add https://ruby.taobao.org/
// gem sources -ahttps://gems.ruby-china.org/ 
// 查看当前'源'
gem sources -l

3-> 更新升级gem

sudo gem update -n /usr/local/bin cocoapods -v 1.0.1

注意1: 如果升级提示 ERROR:  While executing gem ... (OpenSSL::SSL::SSLError)

可能是你的ruby版本问题  或者是  源不对 回到【1】

4-> 安装

4.1 安装cocoapods

sudo gem install -n /usr/local/bin cocoapods

注意1: 如果升级提示

While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.2.1), cocoapods-downloader (< 2.0, >= 1.1.3), cocoapods-trunk (< 2.0, >= 1.2.0), molinillo (~> 0.5.7), xcodeproj (< 2.0, >= 1.4.4), colored2 (~> 3.1), ruby-macho (~> 1.1)

可能你的gem版本问题, 执行下面这句

sudo gem update --system

成功之后在返回4.1

注意2:

GemWrappers: Can not wrap missing file: pod
GemWrappers: Can not wrap missing file: sandbox-pod

表示你的 gem出问题了执行下面的命令

gem uninstall rubygems-update

4.2 查看本地所有cocoapod的版本列表

gem list

4.3 如果某个版本不需要可卸载

sudo gem uninstall cocoapods -v 0.35.0
sudo gem uninstall cocoapods-core -v 0.35.0
sudo gem uninstall cocoapods // 卸载所有

5-> pod初始化

pod 需要从指定的源中获取到第三方库, 所以需要对一个'pod源' 进行初始化, 把所有的库映射到本地

5.1 更换repo镜像为国内服务器

// 移除现有的镜像
pod repo remove master
// 添加新镜像源
pod repo add master https://gitcafe.com/akuandev/Specs.git
pod repo update

已知道的源有

https://gitcafe.com/akuandev/Specs.git
http://git.oschina.net/akuandev/Specs.git
https://git.coding.net/hging/Specs.git

注意如果提示

MydeMacBook-Pro:~ taurin$ pod repo add master https://gitcafe.com/akuandev/Specs.git
[!] To setup the master specs repo, please run `pod setup`.

请执行5.2

5.2 初始化第三方库信息: 把第三方库映射到本地

pod setup

注意如果提示

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress

Cloning into 'master'...
remote: Counting objects: 1975217, done.
remote: Compressing objects: 100% (401/401), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

执行下面指令

cd ~/.cocoapods/
sudo -rm -rf ~/.cocoapods/ 

返回到 5.2

5.3 查找第三方库

pod search tt

注意: 如果在查找的过程中出现Unable to find a pod with name, author, summary, or description matching `tt`

解决办法: 需要把以前查找过的json文件删掉

目录地址/Users/taojian/Library/Caches/CocoaPods/search_index.json

5.4 更新pod映射库

pod repo update

5.5 其他操作

5.4.1 查看当前pod版本

pod --version

5.4.2 查看repo

pod repo list

6-> 创建podfile文件集成第三方库

6.1 新建Podfile

vim Podfile

6.2 编辑podfile文件

- 输入i:进入编辑状态
- 输入dd:删除当前行
- 按ESC:退出编辑模式
- 输入:wq:保存并退出

6.3 Podfile文件的格式

以前你这么写是可以的, 应该是cocoapods0.35.0版本

```objc
platform :ios, '8.0'
pod '框架名字'
pod '框架名字', '~> 版本号'
```

1.0.0以后如果你还是那么写是报错的, pod不成功的, 需要下面的写法 (推荐这么写)

platform :ios, '8.0'
use_frameworks! // SwiftAFNetwoking 是你APP里targets 名如下图所示
target 'SwiftAFNetwoking' do pod 'AFNetworking', '~> 2.6' end

6.4 解析Podfile,安装第三方框架

pod install

6.5 升级第三方框架

pod update

6.6 手动创建podfile文件不用vim命令

直接在已有的项目里把podfile文件复制过来, 利用txt编辑器修改里面的内容, 最后pod install这样也可以的

7-> 出现的问题、与解决办法:

7.1. pod install 之后发现没有xcworkspace文件

解决办法

// 移除cocoapods
1. sudo gem uninstall cocoapods // 可能会让你选择一个版本
// 再安装cocoapods
2. sudo gem install -n /usr/local/bin cocoapods --pre
// 再install
3. pod install

7.2. 但如果cocoapod升级版本以后你会发现上面写的会提示

解决办法: 因为cocoapod 格式改了如下

platform :ios, '8.0'
use_frameworks! // SwiftAFNetwoking 是你APP里targets 名如下图所示
target 'SwiftAFNetwoking' do pod 'AFNetworking', '~> 2.6' end 

再pod install



最新文章

  1. linux复制指定目录下的全部文件到另一个目录中
  2. mac安装Aws cli失败
  3. Objective-c中定义成员变量
  4. JVM&lt;一&gt;----------运行时数据区域
  5. 普通SQL语句可以用Exec执行
  6. JSon_零基础_007_将JSon格式的&quot;数组&quot;字符串转换为Java对象&quot;数组&quot;
  7. 编程之美:1.9高效率安排见面会 图的m着色问题 回溯法
  8. 【ADO.NET】2、各种版本的 简单登录验证
  9. 完整的thinphp+phpexcel实现excel报表的输出(有图有效果)
  10. [重构到模式-Chain of Responsibility Pattern]把Fizz Buzz招式重构到责任链模式
  11. Mac Git 学习笔记
  12. 给js动态创建的对象绑定事件
  13. Spring Security(三十四):10.4 Jackson Support
  14. jQuery 基本选择器 层次选择器 过滤选择器 内容过滤选择器 可见过滤选择器 属性过滤选择器 表单对象属性过滤选择器
  15. java I/O系统 LineNumberReader类
  16. html 之 浮动(待补充)
  17. 设计模式《JAVA与模式》之迭代子模式
  18. python自学——文件处理(强制刷新)
  19. libgdx学习记录10——Particle粒子
  20. centos下mysql自动备份

热门文章

  1. poj 1422 Air Raid (二分匹配)
  2. (七)Redis对键key的操作
  3. 【以前的空间】Poj 3071 Cut the Sequence
  4. Visio分类
  5. CCPC-Winter Camp div2 day1
  6. Redrain 通用菜单控件使用方法和说明(附源码和demo)
  7. [技巧篇]04.使用PowerDesigner逆向生成
  8. 二叉树系列 - 二叉搜索树 - [LeetCode] 中序遍历中利用 pre节点避免额外空间。题:Recover Binary Search Tree,Validate Binary Search Tree
  9. leetcode 刷题日志 2018-3-28
  10. 设置zookeeper开机自启动