iOS使用CocoaPods托管第三方代码

注:以下步骤均是在终端里完成的

一、安装

①由于大陆无法访问一些特定的外网,我们要借助淘宝来访问Cocoa Pods,在终端输入以下两条命令(如果你的mac已经翻墙,可略过①②步)

gem sources —remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
②验证镜像是否指向了淘宝

gem sources -l
如果看到以下信息,证明成功,就继续往下走

*** CURRENT SOURCES ***
http://ruby.taobao.org/
③直接安装就OK了

sudo gem install cocoapods
注:苹果系统升级 OS X EL Capitan 后改为  

sudo gem install -n /usr/local/bin cocoapods
pod setup
安装成功后会有相应的提醒

二、使用

SDWebImage来举例吧

①先看看Cocoapods中更新到什么版本了

pod search SDWebImage
搜索结果:

-> 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.4)

   Asynchronous image downloader with cache support with an UIImageView

   category.

   pod 'SDWebImage', '~> 3.7.4'

   - Homepage: https://github.com/rs/SDWebImage

   - Source:   https://github.com/rs/SDWebImage.git

   - Versions: 3.7.4, 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.4)

     - SDWebImage/MapKit (3.7.4)

     - SDWebImage/WebP (3.7.4)



-> 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)



-> SDWebImageGifWithFLAnimatedImageDemo (1.0.0)

   使用SDWebImage下载图片,使用FLAnimatedImage显示gif图片

   pod 'SDWebImageGifWithFLAnimatedImageDemo', '~> 1.0.0'

   - Homepage:

   https://github.com/zhangping19880920/SDWebImageGifWithFLAnimatedImageDemo

   - Source:  

   https://github.com/zhangping19880920/SDWebImageGifWithFLAnimatedImageDemo.git

   - Versions: 1.0.0 [master repo]



-> 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]




显示当前最新版为3.7.4,把黄色背景的代码复制到剪切板。

②进入项目文件夹下,创建Podfile文件(确保.xcodeproj文件在该目录下,即创建的Podfile文件和.xcodeproj文件在同一目录下

cd 你的项目目录(直接拖进来就行)
vim Podfile
然后就进入到Podfile文件里了。

③对该文件进行编辑,按i就是编辑,按esc就是退出编辑。

按i之后,输入

platform :ios, '7.0'
回车,然后cmd + v,把刚才复制的粘贴到这

pod 'SDWebImage', '~> 3.7.4'
然后esc退出编辑模式

然后输入:wq再回车保存并关闭

④然后执行安装

pod install
然后提示安装成功



Updating local specs repositories


CocoaPods 1.0.0.beta.6 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.


Analyzing dependencies

Downloading dependencies

Installing SDWebImage (3.7.5)

Generating Pods project

Integrating client project


[!] Please close any current Xcode sessions and use `test.xcworkspace` for this project from now on.

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.




⑥安装完成,打开项目就可以使用了。(不要打开xcodeproj文件,以后再打开项目要双击xcworkspace文件)

⑦要想添加多个第三方,直接在第三步中编辑Podfile文件那里复制你要添加的第三方名字和版本就行了,一定要复制粘贴哦,不然自己手敲很容易出错的。



















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值