CocoaPods使用筆記

CocoaPods 使用指南:

最近使用cocoapods 遇到的問題

[!] CDN: trunk Repo update failed - 26 error(s):

參考:http://www.itdecent.cn/p/bf1cbe49cb5d

最近更新Cocoapods遇到的問題:

- ERROR | [iOS] unknown: Encountered an unknown error (CDN: trunk Repo update failed - 2 error(s):

CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/f/8/a/SensorsAnalyticsSDK/2.0.1/SensorsAnalyticsSDK.podspec.json, error: execution expired

CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/f/8/a/SensorsAnalyticsSDK/2.0.2/SensorsAnalyticsSDK.podspec.json, error: execution expired

解決辦法:

cocoapods_specs_url='https://github.com/CocoaPods/Specs.git'

# cocoapods_specs_url='https://cdn.cocoapods.org/'



2019.6.21 更新:更新系統(tǒng)Mac OS 10.15 Beta 版 出現(xiàn)的問題


系統(tǒng)配置
終端錯(cuò)誤信息都很好

根據(jù)錯(cuò)誤信息提示知道是cocoapods路徑問題

解決方案1:

執(zhí)行?

```

brew link --overwrite cocoapods

```


上面的方案報(bào)錯(cuò)

方案2

執(zhí)行

```

brew reinstall cocoapods

brew install ruby

brew link --overwrite cocoapods

```

2019.4.26 更新:本地建立私有庫 執(zhí)行 pod search 操作失敗

```

? ~ pod search AFNetworking

――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

### Command

```

/usr/local/bin/pod search AFNetworking

```

### Report

* What did you do?

* What did you expect to happen?

* What happened instead?

### Stack

```

? CocoaPods : 1.7.0.beta.3

? ? ? ? Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

? ? RubyGems : 2.5.2.3

? ? ? ? Host : Mac OS X 10.14.4 (18E226)

? ? ? Xcode : 10.2.1 (10E1001)

? ? ? ? Git : git version 2.20.1 (Apple Git-117)

Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib

Repositories : BestSpecs - https://gitlab.bestpay.com.cn/mbp/sdk-ios-podspec.git @ 73e2d9ea1ffbb7b856355478ab35723127f37748

? ? ? ? ? ? ? master - https://github.com/CocoaPods/Specs.git @ 64c4782ec389c4040aa1b4b948da9f15fa78549a

```

### Plugins

```

cocoapods-deintegrate : 1.0.3

cocoapods-packager? ? : 1.5.0

cocoapods-plugins? ? : 1.0.0

cocoapods-search? ? ? : 1.0.0

cocoapods-stats? ? ? : 1.0.0

cocoapods-trunk? ? ? : 1.3.1

cocoapods-try? ? ? ? : 1.1.0

```

### Error

```

JSON::ParserError - 784: unexpected token at 'nagement"],"密碼管理SDK":["BestPasswordManagement"],"密碼管理":["BestPasswordManagement"],"life-is-a-boat":["BestPasswordManagement"],"liubing-it@bestpay.com.cn":["BestPasswordManagement"]},"com-mbp-sdk-ios-passwordmanagement":{}}'

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse'

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:252:in `stored_search_index'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:184:in `updated_search_index'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.7.0.beta.3/lib/cocoapods-core/source/manager.rb:115:in `search_by_name'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:87:in `local_search'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-search-1.0.0/lib/cocoapods-search/command/search.rb:63:in `run'

/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.0.beta.3/lib/cocoapods/command.rb:52:in `run'

/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.0.beta.3/bin/pod:55:in `<top (required)>'

/usr/local/bin/pod:22:in `load'

/usr/local/bin/pod:22:in `<main>'

```

――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

[!] Oh no, an error occurred.

Search for existing GitHub issues similar to yours:

https://github.com/CocoaPods/CocoaPods/search?q=784%3A+unexpected+token+at+%27nagement%22%5D%2C%22%E5%AF%86%E7%A0%81%E7%AE%A1%E7%90%86SDK%22%3A%5B%22BestPasswordManagement%22%5D%2C%22%E5%AF%86%E7%A0%81%E7%AE%A1%E7%90%86%22%3A%5B%22BestPasswordManagement%22%5D%2C%22life-is-a-boat%22%3A%5B%22BestPasswordManagement%22%5D%2C%22liubing-it%40bestpay.com.cn%22%3A%5B%22BestPasswordManagement%22%5D%7D%2C%22com-mbp-sdk-ios-passwordmanagement%22%3A%7B%7D%7D%27&type=Issues

If none exists, create a ticket, with the template displayed above, on:

https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:

https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

Looking for related issues on cocoapods/cocoapods...

Found no similar issues. To create a new issue, please visit:

https://github.com/cocoapods/cocoapods/issues/new

```

本地search_index 問題,解決辦法是刪除該文件即可

sudo rm??/Library/Caches/CocoaPods/search_index.json

2018.12.4 更新:系統(tǒng)更新導(dǎo)致cocoapods使用出錯(cuò)

升級macOS Mojave之后,cocoapods不能正常使用了,這是蘋果一貫的問題,遇到大版本系統(tǒng)升級,之前的一些軟件就不能正常使用了。

終端輸入

sudo gem update –system

顯示如下錯(cuò)誤

ERROR: While executing gem … (Gem::FilePermissionError)

You don’t have write permissions for the /usr/bin directory.

解決辦法:

輸入一下命令:

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

2018.9.22 更新:ruby 地址更新

https://gems.ruby-china.com


參照:https://gems.ruby-china.org

1.安裝指南

安裝方式異常簡單 , Mac 下都自帶 ruby,使用 ruby 的 gem 命令即可下載安裝:

$ sudo gem install cocoapods

$ pod setup

另外,ruby 的軟件源 https://rubygems.org 因?yàn)槭褂玫氖莵嗰R遜的云服務(wù),所以被墻了,需要更新一下 ruby 的源,使用如下代碼將官方的 ruby 源替換成國內(nèi)淘寶的源:

gem sources -l? ????????//使用該方法查看本地gem安裝的鏡像地址

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

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

gem sources --add https://gems.ruby-china.com/?

gem sources -l

還有一點(diǎn)需要注意,pod setup在執(zhí)行時(shí),會輸出Setting up CocoaPods master repo,但是會等待比較久的時(shí)間。這步其實(shí)是 Cocoapods 在將它的信息下載到 ~/.cocoapods目錄下,如果你等太久,可以試著 cd 到那個(gè)目錄,用du -sh *來查看下載進(jìn)度。你也可以參考本文接下來的使用 cocoapods 的鏡像索引一節(jié)的內(nèi)容來提高下載速度。

然后執(zhí)行安裝命令

在項(xiàng)目目錄下創(chuàng)建文件Podfile

仿照下規(guī)則書寫

platform :ios, '8.0'

use_frameworks!

target 'MyApp' do

? pod 'AFNetworking', '~> 2.6'

? pod 'ORStackView', '~> 3.0'

? pod 'SwiftyJSON', '~> 2.3'

end

Tip: CocoaPods provides a pod init command to create a Podfile with smart defaults. You should use it.

執(zhí)行下命令給項(xiàng)目安裝cocoaPods

$ pod install

2.版本控制

? pod 'AFNetworking', '~> 2.6'

執(zhí)行pod update 更新庫 版本控制有一下幾種方式:

? 1)引用第三方庫的后邊不添加? 每次更新為最新的

? 2)添加 '2.6' 則是注明了第三方庫的使用版本為固定的

? 3)使用'~> 2.6' 說明庫的版本為2.6以上的版本? 即最新版本

? 邏輯運(yùn)算符

? '> 0.1' Any version higher than 0.1

? '>= 0.1' Version 0.1 and any higher version

? '< 0.1' Any version lower than 0.1

? '<= 0.1' Version 0.1 and any lower version


? 樂觀的運(yùn)算符 an optimistic operator ~>:

? '~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher //0.1.2至0.2

? '~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher? //0.1至1.0

? '~> 0' Version 0 and higher, this is basically the same as not having it.


3.

cocoapods 使用常見的問題

1.安裝第三方庫在項(xiàng)目中導(dǎo)入的時(shí)候提示找不到文件

這個(gè)一般情況下是在build settings -->search paths header search paths --> User Header Search Paths ?添加 $(PODS_ROOT) 選擇:recursive(會在相應(yīng)的目錄遞歸搜索文件)

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

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

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