CocoaPods的安装(以下命令均在终端下操作)

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

sudo gem install cocoapods
pod setup

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

sudo gem update --system

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

gem sources --remove http://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l

4.(验证)输入下面命令后,

gem sources -l

如果出现下面

*** CURRENT SOURCES ***

https://ruby.taobao.org/

5.此时就可以进行安装,

sudo gem install cocoapods

出现以下

Successfully installed cocoapods-0.39.0
Parsing documentation for cocoapods-0.39.0
1 gem installed

CocoaPods的使用介绍

1.使用时需要(在想要加入第三方的工程下)新建一个名为Podfile的文件(先将工程路径拖进终端,使在此文件中创建)

cd /Users/lanou3g/Desktop/未命名文件夹/text
jinzhao:text lanou3g$ touch Podfile

2.然后将依赖的库(第三方)名字依次列在文件中

jinzhao:text lanou3g$ vim Podfile

//编写方式,如以下
pod 'SDWebImage', '~>3.7'

终端进入
vim Podfile(如果存在直接打开,不存在创建后打开)
此时进入文件,如果是编辑模式,即可以进行编辑,或者是命令模式
编辑模式—>ESC+shift+冒号键+w键,此时可以写入
编辑模式—>ESC+shift+冒号键+q键,此时已经离开
编辑模式—>ESC+shift+冒号键+wq键,此时写入并离开
编辑模式—>ESC+shift+冒号键+wq!键,强制写入并离开
命令模式—>i键—>进入编辑模式
set nu:显示行号
ESC后 输入dd 可以删掉一行

3.然后编辑好的Podfile文件放到根目录中,执行如下命令即可:

cd "you project home"//此为将文件放到根目录,小编本就在根目录下创建,故此步骤可省略
pod install//圆荚体安装

4.得到,例如出现以下,即为加载完毕

Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing SDWebImage (3.7.3)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `text.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total
pod installed.

5.你如果不知道cocoaPods管理的库中,是否有你想要的库,那么你可以同过pod search命令进行查找,以下是我用pod 'SDWebImage', '~>3.7'查找到的所有可用的库:

-> ComponentKit+SDWebImage (0.0.2) [DEPRECATED]
   CKNetworkImageDownloading implementation for SDWebImage.
   pod 'ComponentKit+SDWebImage', '~> 0.0.2'
   - Homepage: https://github.com/eyeem/ComponentKit-SDWebImage
   - Source:   https://github.com/eyeem/ComponentKit-SDWebImage.git
   - Versions: 0.0.2, 0.0.1 [master repo]


-> DSActivityIndicatorSDWebImage (1.0.6)
   The easiest way to add a UIActivityView to your SDWebImage view.
   pod 'DSActivityIndicatorSDWebImage', '~> 1.0.6'
   - Homepage: https://github.com/diejmon/UIActivityIndicator-for-SDWebImage
   - Source:   https://github.com/diejmon/UIActivityIndicator-for-SDWebImage.git
   - Versions: 1.0.6, 1.0 [master repo]


-> IMY_SDWebImage_Wrapper (1.0)
   SDWebImageView 进度条支持
   pod 'IMY_SDWebImage_Wrapper', '~> 1.0'
   - Homepage: https://github.com/meiyoudev/IMY_SDWebImage_Wrapper
   - Source:   https://github.com/meiyoudev/IMY_SDWebImage_Wrapper.git
   - Versions: 1.0 [master repo]


-> SDWebImage (3.7.3)
   Asynchronous image downloader with cache support with an UIImageView
   category.
   pod 'SDWebImage', '~> 3.7.3'
   - Homepage: https://github.com/rs/SDWebImage
   - Source:   https://github.com/rs/SDWebImage.git
   - Versions: 3.7.3, 3.7.2, 3.7.1, 3.7.0, 3.6, 3.5.4, 3.5.2, 3.5.1, 3.5, 3.4,
   3.3, 3.2, 3.1, 3.0, 2.7.4, 2.7, 2.6, 2.5, 2.4 [master repo]
   - Subspecs:
     - SDWebImage/Core (3.7.3)
     - SDWebImage/MapKit (3.7.3)
     - SDWebImage/WebP (3.7.3)


-> SDWebImage+ExtensionSupport (3.7.1.2)
   Asynchronous image downloader with cache support with an UIImageView
   category. Added SD_APP_EXTENSION macro for ios8 extensions
   pod 'SDWebImage+ExtensionSupport', '~> 3.7.1.2'
   - Homepage: https://github.com/rs/SDWebImage
   - Source:   https://github.com/glassoff/SDWebImage.git
   - Versions: 3.7.1.2, 3.7.1.1 [master repo]
   - Subspecs:
     - SDWebImage+ExtensionSupport/Core (3.7.1.2)
     - SDWebImage+ExtensionSupport/MapKit (3.7.1.2)


-> SDWebImage-Category (1.4)
   方便快捷的为UIImageView加上下载进度条,支持:下载失败显示裂图,显示 点击下载图片
   pod 'SDWebImage-Category', '~> 1.4'
   - Homepage: https://github.com/li6185377/SDWebImage-Category
   - Source:   https://github.com/li6185377/SDWebImage-Category.git
   - Versions: 1.4, 1.3, 1.2, 1.1.1, 1.1 [master repo]


-> SDWebImage-ProgressView (0.4.0)
   Category on UIImageView, adding a progress view while images are downloaded
   using SDWebImage.
   pod 'SDWebImage-ProgressView', '~> 0.4.0'
   - Homepage: https://github.com/kevinrenskers/SDWebImage-ProgressView
   - Source:   https://github.com/kevinrenskers/SDWebImage-ProgressView.git
   - Versions: 0.4.0, 0.3.1, 0.3.0, 0.2.0, 0.1.0 [master repo]


-> SDWebImageFix (3.7.3.2)
   Asynchronous image downloader with cache support with an UIImageView
   category.
   pod 'SDWebImageFix', '~> 3.7.3.2'
   - Homepage: https://github.com/jumperb/SDWebImage
   - Source:   https://github.com/jumperb/SDWebImage.git
   - Versions: 3.7.3.2, 3.7.3.1 [master repo]
   - Subspecs:
     - SDWebImageFix/Core (3.7.3.2)
     - SDWebImageFix/MapKit (3.7.3.2)
     - SDWebImageFix/WebP (3.7.3.2)


-> UIActivityIndicator-for-SDWebImage (1.2)
   The easiest way to add a UIActivityView to your SDWebImage view.
   pod 'UIActivityIndicator-for-SDWebImage', '~> 1.2'
   - Homepage: https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage
   - Source:  
   https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage.git
   - Versions: 1.2, 1.1, 1.0.5, 1.0.4, 1.0.3, 1.0.2, 1.0.0 [master repo]


-> UIActivityIndicator-for-SDWebImage+UIButton (1.2)
   The easiest way to add a UIActivityView to your SDWebImage view.
   pod 'UIActivityIndicator-for-SDWebImage+UIButton', '~> 1.2'
   - Homepage: https://github.com/nobre84/UIActivityIndicator-for-SDWebImage
   - Source:   https://github.com/nobre84/UIActivityIndicator-for-SDWebImage.git
   - Versions: 1.2 [master repo]


-> UIImageView+SDWebImage_M13ProgressSuite (0.1.1)
   Category of UIImageView, downloaded with SDWebImage, progressed with
   M13ProgressSuite.
   pod 'UIImageView+SDWebImage_M13ProgressSuite', '~> 0.1.1'
   - Homepage: https://github.com/Jowyer/UIImageView-SDWebImage_M13ProgressSuite
   - Source:  
   https://github.com/Jowyer/UIImageView-SDWebImage_M13ProgressSuite.git
   - Versions: 0.1.1, 0.1.0 [master repo]

6.现在,你的所有第三方库都已经下载完成并且设置好了编译参数和依赖,你只需记住如下2点即可:

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


ZhangJinzhao
80 声望2 粉丝

引用和评论

0 条评论