集成cocoapods及遇到的一些問題

一、集成cocoapods的流程有如下幾步
1.移除現(xiàn)有的Ruby**

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

2.使用淘寶鏡像**

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

淘寶的那個鏡像https://ruby.taobao.org/已經(jīng)不可用了。所以我們現(xiàn)在用最新支持的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.環(huán)境問題

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)

原因是依賴的環(huán)境版本過低需要更新:用:$sudo gem update --system命令更新環(huán)境;更新之后就可以重新安裝了。

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.出現(xiàn)Operation not permitted - /usr/bin/xcodeproj的問題
sudo gem install -n /usr/local/bin cocoapods --pre這段命令代替sudo gem install cocoa pods

4、執(zhí)行pod install還是pod update如果卡在了Analyzing dependencies不動:原因在于當執(zhí)行以上兩個命令的時候會升級CocoaPods的spec倉庫,加一個參數(shù)可以省略這一步,然后速度就會提升不少。加參數(shù)的命令如下:

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  

查看版本后出現(xiàn)如下情況

# 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-<name> --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,進入編輯模式,輸入以下格式內(nè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就是當前項目的名字

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容