Cocoapods 的安装 及使用

最近公司要开个新项目。所以重新安装下电脑上的Cocoapods。具体的执行步骤如下 ,希望对大家有所帮助。

首先,打开终端输入窗口。(本文中出现的$都不需要输入,只是为了方便大家知道哪个是命令)

检查当前的gem source.

$ gem sources -l

如果没有 任何的ruby源 命令行反馈提示为:command not found;   //这种情况一般表现在之前电脑上没装过Cocoapods的情况。


如果电脑上之前安装过Cocoapods,命令行反馈提示为:

*** CURRENT SOURCES ***


https://rubygems.org/

或者

*** CURRENT SOURCES ***

https://taobao.org/                       //这里 这两个地址为两个不同地址的镜像文件。一个是ruby的镜像文件 一个是淘宝的镜像文件。

如果 你曾经安装的是第一种情况下的镜像文件的话 ,建议删除,重新安装淘宝的镜像文件 (因为第一个网址被我大天朝无情屏蔽了 你们懂的 当然如果你有可用的VPN 应该也可以下载第一种,这里我下载的是第二种)。

如果命令行 反馈出的是第一种情况 :输入命令

$gem sources --remove https://rubygems.org/  //移除ruby镜像文件

正常的命令行反馈为:

https://rubygems.org/ removed from sources


$gem sources -a https://ruby.taobao.org/ //安装淘宝镜像文件(这里注意:如果 你电脑上没装过Cocoapods 从这一步开始)


正常的命令行反馈为:

https://ruby.taobao.org/ added to sources

以下将执行安装Cocoapods的操作(到这一步 无论是哪种情况 都已经安装了淘宝的镜像文件,所以以下步骤适用所有情况)

命令行执行:

$sudo gem install cocoapods      //执行安装下载Cocoapods命令

如果 你电脑上有密码  会叫你输入密码 注意 你输入的密码 默认是不显示的 直接输入密码 回车即可

输入密码会等待一段时间 命令行反馈为:

liuxhdeMBP:~ liuxh$ sudo gem install cocoapods

Password:

Fetching: i18n-0.7.0.gem (100%)

Successfully installed i18n-0.7.0

Fetching: thread_safe-0.3.5.gem (100%)

Successfully installed thread_safe-0.3.5

Fetching: tzinfo-1.2.2.gem (100%)

Successfully installed tzinfo-1.2.2

Fetching: minitest-5.8.4.gem (100%)

Successfully installed minitest-5.8.4

Fetching: activesupport-4.2.5.2.gem (100%)

Successfully installed activesupport-4.2.5.2

Fetching: nap-1.1.0.gem (100%)

Successfully installed nap-1.1.0

Fetching: fuzzy_match-2.0.4.gem (100%)

Successfully installed fuzzy_match-2.0.4

Fetching: cocoapods-core-0.39.0.gem (100%)

Successfully installed cocoapods-core-0.39.0

Fetching: claide-0.9.1.gem (100%)

Successfully installed claide-0.9.1

Fetching: colored-1.2.gem (100%)

Successfully installed colored-1.2

Fetching: xcodeproj-0.28.2.gem (100%)

Successfully installed xcodeproj-0.28.2

Fetching: cocoapods-downloader-0.9.3.gem (100%)

Successfully installed cocoapods-downloader-0.9.3

Fetching: cocoapods-plugins-0.4.2.gem (100%)

Successfully installed cocoapods-plugins-0.4.2

Fetching: cocoapods-search-0.1.0.gem (100%)

Successfully installed cocoapods-search-0.1.0

Fetching: cocoapods-stats-0.6.2.gem (100%)

Successfully installed cocoapods-stats-0.6.2

Fetching: cocoapods-try-0.5.1.gem (100%)

Successfully installed cocoapods-try-0.5.1

Fetching: netrc-0.7.8.gem (100%)

Successfully installed netrc-0.7.8

Fetching: cocoapods-trunk-0.6.4.gem (100%)

Successfully installed cocoapods-trunk-0.6.4

Fetching: molinillo-0.4.4.gem (100%)

Successfully installed molinillo-0.4.4

Fetching: escape-0.0.4.gem (100%)

Successfully installed escape-0.0.4

Fetching: cocoapods-0.39.0.gem (100%)

Successfully installed cocoapods-0.39.0

Parsing documentation for i18n-0.7.0

Installing ri documentation for i18n-0.7.0

Parsing documentation for thread_safe-0.3.5

Installing ri documentation for thread_safe-0.3.5

Parsing documentation for tzinfo-1.2.2

Installing ri documentation for tzinfo-1.2.2

Parsing documentation for minitest-5.8.4

Installing ri documentation for minitest-5.8.4

Parsing documentation for activesupport-4.2.5.2

unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping

Installing ri documentation for activesupport-4.2.5.2

Parsing documentation for nap-1.1.0

Installing ri documentation for nap-1.1.0

Parsing documentation for fuzzy_match-2.0.4

Installing ri documentation for fuzzy_match-2.0.4

Parsing documentation for cocoapods-core-0.39.0

Installing ri documentation for cocoapods-core-0.39.0

Parsing documentation for claide-0.9.1

Installing ri documentation for claide-0.9.1

Parsing documentation for colored-1.2

Installing ri documentation for colored-1.2

Parsing documentation for xcodeproj-0.28.2

Installing ri documentation for xcodeproj-0.28.2

Parsing documentation for cocoapods-downloader-0.9.3

Installing ri documentation for cocoapods-downloader-0.9.3

Parsing documentation for cocoapods-plugins-0.4.2

Installing ri documentation for cocoapods-plugins-0.4.2

Parsing documentation for cocoapods-search-0.1.0

Installing ri documentation for cocoapods-search-0.1.0

Parsing documentation for cocoapods-stats-0.6.2

Installing ri documentation for cocoapods-stats-0.6.2

Parsing documentation for cocoapods-try-0.5.1

Installing ri documentation for cocoapods-try-0.5.1

Parsing documentation for netrc-0.7.8

Installing ri documentation for netrc-0.7.8

Parsing documentation for cocoapods-trunk-0.6.4

Installing ri documentation for cocoapods-trunk-0.6.4

Parsing documentation for molinillo-0.4.4

Installing ri documentation for molinillo-0.4.4

Parsing documentation for escape-0.0.4

Installing ri documentation for escape-0.0.4

Parsing documentation for cocoapods-0.39.0

Installing ri documentation for cocoapods-0.39.0

21 gems installed                        //这一段代码 就是表示 你下载成功了 


然后 执行命令:

$pod setup    //设置 cocoapods 


执行完这句 命令行提示为:

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

到这里 恭喜你! 您已成功安装Cocoapods。

如何使用CocoaPods:

1.在Xcode上新建一个工程,在终端中进入程序根目录下,输入:pod init

这里会创建一个podfile文件;

2.进入podfile文件,可以利用命令,vi podfile ----> pod 'AFNetworking'-->esc --->shift + 双击Z ,这时退出并保存了;(注:如果直接打开文件输入pod ‘AFNetworking’可能会出错,建议使用终端输入

3.输入:pod install ,这时请耐心等待下载,等下载好。打开工程 那么这个库就已经存在你的项目中了

5.启动工程的时候选择使用pod生成的那个工程名。

6.删除cocoaPods中的某个类库

如果自己不想使用某个类库后,想删除某个三方库,那么我们就需要重新配置podfile文件,在podfile文件中直接打开,删除对应的文字就可以解决掉,比如直接把pod ‘AFNetworking’删除即可,然后执行pod install


7.删除cocoaPods我如果觉得不想使用cocoaPods,我想删除,那么我需要删除一下文件

删除工程文件夹下的Podfile、Podfile.lock和Pods文件夹。

删除xcworkspace文件。

打开xcodeproj文件,删除项目中的libpods.a和Pods.xcconfig引用:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值