CocoaPods安装,iOS程序第三方框架的依赖管理

每种语言发展到一个阶段,就会出现相应的依赖管理工具,例如 Java 语言的 Maven,nodejs 的 npm。随着 iOS 开发者的增多,业界也出现了为 iOS 程序提供依赖管理的工具,它的名字叫做:CocoaPods

CocoaPods 的安装和使用介绍

安装

如果你的 gem 太老,可能也会有问题,可以尝试用如下命令升级 gem:

sudo gem update --system

  

查看当前ruby 的软件源

gem sources -l

  

ruby 的软件源 https://rubygems.org 因为使用的是亚马逊的云服务,所以被墙了,需要更新一下 ruby 的源,使用如下代码将官方的 ruby 源替换成国阿里云的源:

gem sources --remove https://rubygems.org/
gem sources -a  https://gems.ruby-china.com // 
http://rubygems-china.oss.aliyuncs.com/
这个更新Mac系统10.14.x后就不起作用了,后面会导致cocoaPods升级不到最新, gem sources -l

  

安装方式异常简单 , Mac 下都自带 ruby,使用 ruby 的 gem 命令即可下载安装:

安装cocoapods

sudo gem install cocoapods 

上面可能会报错:

bogon:~ HJiang$ sudo gem install cocoapods
Password:
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/fuzzy_match

 

本人是这样解决的:

 

sudo gem install -n /usr/local/bin cocoapods
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.2.1.gem (100%)
Successfully installed cocoapods-core-1.2.1
Fetching: cocoapods-1.2.1.gem (100%)
Successfully installed cocoapods-1.2.1
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-1.2.1
Installing ri documentation for cocoapods-core-1.2.1
Parsing documentation for cocoapods-1.2.1
Installing ri documentation for cocoapods-1.2.1
3 gems installed

  

使用 CocoaPods 的镜像索引

pod setup

 这步可能会有点慢,本人大概用了40分钟,而且网络很好的情况下.

pod setup可能会报如下错误,本人使用电脑连接手机热点解决的.

HJiangPro:~ HJiang$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress

Cloning into 'master'...
fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

 成功:

HJiangPro:~ HJiang$ pod setup
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Enumerating objects: 568, done.        
  remote: Counting objects: 100% (568/568), done.        
  remote: Compressing objects: 100% (509/509), done.        
  remote: Total 2578734 (delta 237), reused 35 (delta 35), pack-reused 2578166        
  Receiving objects: 100% (2578734/2578734), 587.65 MiB | 303.00 KiB/s, done.
  Resolving deltas: 100% (1512641/1512641), done.
  Checking out files: 100% (281045/281045), done.

CocoaPods 1.6.0.beta.2 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.6.0.beta.2

Setup completed

 

新建Podfile,编辑内容:

#要兼容的最低版本号
platform :ios, ‘8.0’


target 'testCocoaPods’ do

  #如果是swift项目,这句话保留;如果是OC项目,这句话要删除
  #use_frameworks!

  #添加第三方类库
  pod 'AFNetworking'

  #添加指定版本号的第三方类库
  pod 'SVProgressHUD', '1.1.3'


end  

也可以使用命令行方式,进入项目的目录,使用终端

pod init  

这样自动生成Podfile文件.

新增项目testCocoaPods,把Podfile拖入项目中,跟.xcodeproj同目录,然后运行

pod install

待安装完成后

现在,你的所有第三方库都已经下载完成并且设置好了编译参数和依赖,需要记住:

  1. 使用 CocoaPods 生成的 .xcworkspace 文件来打开工程,而不是以前的 .xcodeproj 文件。
  2. 每次更改了 Podfile 文件,你需要重新执行一次pod update命令。

 

cocoapods升级

通过命令:

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

 

成功提示:

bogon:~ HJiang$ sudo gem install -n /usr/local/bin cocoapods --pre
Fetching: claide-1.0.2.gem (100%)
Successfully installed claide-1.0.2
Fetching: xcodeproj-1.5.2.gem (100%)
Successfully installed xcodeproj-1.5.2
Fetching: molinillo-0.6.3.gem (100%)
Successfully installed molinillo-0.6.3
Fetching: cocoapods-core-1.4.0.beta.1.gem (100%)
Successfully installed cocoapods-core-1.4.0.beta.1
Fetching: cocoapods-1.4.0.beta.1.gem (100%)
Successfully installed cocoapods-1.4.0.beta.1
Parsing documentation for claide-1.0.2
Installing ri documentation for claide-1.0.2
Parsing documentation for xcodeproj-1.5.2
Installing ri documentation for xcodeproj-1.5.2
Parsing documentation for molinillo-0.6.3
Installing ri documentation for molinillo-0.6.3
Parsing documentation for cocoapods-core-1.4.0.beta.1
Installing ri documentation for cocoapods-core-1.4.0.beta.1
Parsing documentation for cocoapods-1.4.0.beta.1
Installing ri documentation for cocoapods-1.4.0.beta.1
5 gems installed

 

xcode cocoapods插件 cocoapods-xcode-plugin

 

转载于:https://www.cnblogs.com/HJiang/p/7228166.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值