集成cocoapods及遇到的一些问题

一、集成cocoapods的流程有如下几步
1.移除现有的Ruby**

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

2.使用淘宝镜像**

$gem sources -a https://gems.ruby-china.org/

淘宝的那个镜像https://ruby.taobao.org/已经不可用了。所以我们现在用最新支持的ruby镜像https://gems.ruby-china.org/

3.验证当前ruby版本

$gem sources -l

成功后提示:

*** CURRENT SOURCES ***
https://gems.ruby-china.org/

4.开始安装cocoapods

$sudo gem install cocoapods

或者

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

不过按这个流程走可能会遇到很多问题的

二、遇到的问题及解决方法
1.环境问题

ERROR:  While executing gem ... (Gem::DependencyError)Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.2.0), cocoapods-downloader (< 2.0, >= 1.1.3), cocoapods-trunk (< 2.0, >= 1.1.2), molinillo (~> 0.5.5), xcodeproj (< 2.0, >= 1.4.1)

原因是依赖的环境版本过低需要更新:用:$sudo gem update --system命令更新环境;更新之后就可以重新安装了。

2.报证书错误

ERROR:  SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR:  You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
ERROR:  SSL verification error at depth 2: self signed certificate in certificate chain (19)
ERROR:  Root certificate is not trusted (/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA)

解决方式:

$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem

3.出现Operation not permitted - /usr/bin/xcodeproj的问题
sudo gem install -n /usr/local/bin cocoapods --pre这段命令代替sudo gem install cocoa pods

4、执行pod install还是pod update如果卡在了Analyzing dependencies不动:原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少。加参数的命令如下:

pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

5.如果需要更新ruby的话
5.1查看ruby版本

$ruby -v

5.2如果提示command not found 请先安装rvm

$curl -L get.rvm.io | bash -s stable  

查看版本后出现如下情况

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.0]
ruby-head

# for forks use: rvm install ruby-head- --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.26]
jruby[-9.1.7.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx[-3.71]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1[.2.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

3.这里我们安装2.2.2:
$rvm install 2.2.2
安装成功

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.12/x86_64/ruby-2.2.2.tar.bz2
Checking requirements for osx.
Installing requirements for osx.
Updating system............................
Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, readline, libksba, openssl..........
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
ruby-2.2.2 - #configure
ruby-2.2.2 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 6854k  100 6854k    0     0  86477      0  0:01:21  0:01:21 --:--:-- 97394
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.2.2 - #validate archive
ruby-2.2.2 - #extract
ruby-2.2.2 - #validate binary
ruby-2.2.2 - #setup
ruby-2.2.2 - #gemset created /Users/power/.rvm/gems/ruby-2.2.2@global
ruby-2.2.2 - #importing gemset /Users/power/.rvm/gemsets/global.gems............
ruby-2.2.2 - #generating global wrappers........
ruby-2.2.2 - #gemset created /Users/power/.rvm/gems/ruby-2.2.2
ruby-2.2.2 - #importing gemsetfile /Users/power/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.2 - #generating default wrappers........
Updating certificates in '/etc/openssl/cert.pem'.
mkdir: /etc/openssl: Permission denied
mkdir -p "/etc/openssl" failed, retrying with sudo
power password required for 'mkdir -p /etc/openssl': 
and sudo mkdir worked

三、简单的使用
1.终端中,cd到项目总目录(注意:包含PodTest文件夹、PodTest.xcodeproj、PodTestTest的那个总目录)
2.建立Podfile(配置文件)
接着上一步,终端输入 vim Podfile、键盘输入 i,进入编辑模式,输入以下格式内容:

platform :ios, '8.0'
#use_frameworks!个别需要用到它,比如reactiveCocoa
target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end

或者

 platform :ios, '8.0'
#use_frameworks!个别需要用到它,比如reactiveCocoa
def pods
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
target 'MyApp' do
pods
end

其中MyApp就是当前项目的名字

你可能感兴趣的:(集成cocoapods及遇到的一些问题)