[TOC]
安裝
- 更換Ruby鏡像地址
(taobao鏡像地址已換為https,需注意)(已更換的,則跳過(guò))
$ gem sources -a https://ruby.taobao.org/
MARK:淘寶源不再維護(hù),由 Ruby China 負(fù)責(zé)。Ruby China 源地址:https://gems.ruby-china.com/ ,如果遇到 SSL 證書(shū)問(wèn)題,你又無(wú)法解決,請(qǐng)直接用 https://gems.ruby-china.com
避免 SSL 的問(wèn)題。
$ gem sources --add https://gems.ruby-china.com
$ gem sources --remove https://rubygems.org/
$ gem sources -l
# 確保只有 https://gems.ruby-china.com
- 安裝命令
$ sudo gem install cocoapods
- 如果安裝出現(xiàn)這種錯(cuò)誤提示,則使用下邊的命令安裝
// 錯(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
- 如果提示這個(gè)錯(cuò)誤,更新一下gem,然后再安裝
ERROR: While executing gem ... (TypeError)
no implicit conversion of nil into String
// 更新gem
sudo gem update --system
降低版本或卸載
- 查看gems中本地程序包
$ gem list
- 移除cocoapods 程序包(all或者指定版本)
$ sudo gem uninstall cocoapods
$ sudo gem uninstall cocoapods-core
$ sudo gem uninstall cocoapods-downloader
$ sudo gem uninstall cocoapods-plugins
$ sudo gem uninstall cocoapods-search
$ sudo gem uninstall cocoapods-stats
$ sudo gem uninstall cocoapods-trunk
$ sudo gem uninstall cocoapods-try
使用
- 查看是否支持
$ pod search SDWebImage
- 新建一個(gè)名為 Podfile 的文件,以如下格式,將依賴(lài)的庫(kù)名字依次列在文件中,如下,然后你將編輯好的 Podfile 文件放到你的項(xiàng)目根目錄中(注意,平臺(tái)號(hào)對(duì)應(yīng)工程的deployment target,必須加上)
$ cd /Users/wangzz/Desktop/Demo
$ touch Podfile
舊版本的配置寫(xiě)法
platform :ios, '7.0'
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.0.0'
pod 'AFNetworking', '~> 3.0.4' #網(wǎng)絡(luò)庫(kù)
1.0版本之后,格式有了些變化
use_frameworks! # 如果引入swift庫(kù),則需要加這句
platform :ios, '9.0' #平臺(tái)號(hào)
target 'MyApp' do #工程名
pod 'AFNetworking', '~> 3.0.4' #網(wǎng)絡(luò)庫(kù)
pod 'RDVTabBarController', '~> 1.1.9' #tabbar
pod 'Masonry', '~> 0.6.4' #自動(dòng)布局
pod 'ReactiveCocoa', '~> 4.0.1'
pod 'WebViewJavascriptBridge', '~> 5.0' #JS橋接
end
- 在命令行通過(guò)cd指令進(jìn)入到項(xiàng)目根目錄
- 執(zhí)行"pod install" (如果終端出現(xiàn)updating local specs repositories,那么請(qǐng)用ctrl+c強(qiáng)制結(jié)束命令進(jìn)程,然后執(zhí)行 pod install --verbose --no-repo-update)
- 現(xiàn)在,你的所有第三方庫(kù)都已經(jīng)下載完成并且設(shè)置好了編譯參數(shù)和依賴(lài),你只需要記住如下 2 點(diǎn)即可:
-- 使用 CocoaPods 生成的 .xcworkspace 文件來(lái)打開(kāi)工程,而不是以前的 .xcodeproj 文件。
-- 每次更改了 Podfile 文件,你需要重新執(zhí)行一次pod update命令。