Cocoapods的安装以及使用

在网上看博客,看了好多次,都没有学会cocoapods,今天上午浪费了一上午的时间,终于算是学会了。其实也是很简单的。

iOS 新版 CocoaPods 安装流程

1.换掉现有Ruby默认源(由于好多人都没有FQ,所以我们将rubygems换掉,采用taobao的,如果有的是直接FQ的话,可以直接使用rubygems)

$gem sources --remove https://rubygems.org/

2.采用taobao的源

$gem sources -a https://ruby.taobao.org/

3.这里是验证是否替换成功

$gem sources -l

如果成功的话,终端显示的是

CURRENT SOURCES 

https://ruby.taobao.org/

这代表已经替换成功了

4.接下来就是要安装CocoaPods

(1) $sudo gem install cocoapods 备注:苹果系统升级 OS X EL Capitan 后改为$sudo gem install -n /usr/local/bin cocoapods

(2) $pod setup

5.更新gem

$sudo gem update --system

  1. 新建工程,并在终端用cd指令到文件夹内

$pod search 第三方 

(这里是可以查看第三方库的,在search后面输入自己想要查看的第三方库名称)

7.新建文件 vim “Podfile”,

$vim Podfile

写入以下内容并保存小提示:(终端vim文件按 i 可编辑,esc 退出编辑,:wq 可保存退出)

platform:ios, '6.0' 

pod 'AFNetworking', '~> 2.3.1' <-------第三方

platform :ios, '7.0'

inhibit_all_warnings!

pod 'JT3DScrollView', '~> 1.0'

pod 'Masonry'

pod 'pop', '~> 1.0.6'

pod 'KeepLayout', :git => 'https://github.com/iMartinKiss/KeepLayout'

pod 'RZTransitions', '~> 1.0'

pod 'OBShapedButton'

pod 'FMDB', '~> 2.5'

pod 'AFNetworking', '~> 2.6.0'

pod 'SDWebImage', '~> 3.7.3'

pod 'FXBlurView', '~> 1.6.4'

上面这些是我需要的一些第三方的例子,可以直接写在Podfile文件当中

8.导入第三方库

$pod install 

(这里是利用pod将第三方加入到自己的工程中去)

9.退出终端 

这样cocoa pods就这样成功安装了,第三方也导入到自己的工程中去了。

以下是我用以前的安装流程安装时出现的一些错误

终端 cocoapods 下载bug调试:

错误1:

Error fetching http://ruby.taobao.org/:

bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)

解决方案:把安装流程中 $gem sources -a http://ruby.taobao.org/ ---改为---->$gem sources -a https://ruby.taobao.org/

错误2:

ERROR: While executing gem ... (Errno::EPERM)

Operation not permitted - /usr/bin/pod

解决方案:苹果系统升级OS X EL Capitan后会出现的插件错误,将安装流程 4.安装CocoaPods 的 (1)sudo gem install cocoapods ——>改为sudo gem install -n /usr/local/bin cocoapods

错误3:

[!] Unable to satisfy the following requirements: - AVOSCloud (~> 3.1.6.3) required by Podfile

Specs satisfying the AVOSCloud (~> 3.1.6.3) dependency were found, but they required a higher minimum deployment target.

解决方案:安装流程:Podfile文件中 platform:ios, ‘6.0’ 后边的 6.0 是平台版本号,一定要加上

原文地址:https://www.cnblogs.com/luoxiaofu/p/5519465.html