一、Cocoapods介紹
用來集中管理第三方庫.
作用:導入第三方庫 和 檢測并更新第三方庫
優(yōu)點:無論是ARC的第三方還是MRC的第三方都可以通過cocoapods統(tǒng)一管理,大大提高開發(fā)效率。
二、Cocoapods的安裝
1.更換ruby鏡像地址--速度會加快
刪除鏡像 gem sources --remove https://rubygems.org/
添加淘寶鏡像 gem sources -a https://ruby.taobao.org/
查看當前鏡像 gem sources -l
2.安裝cocoa pods
安裝 sudo gem install cocoa pods
3.驗證安裝是否成功
命令行 pod 出現(xiàn)pod的參數(shù)即可。
三、安裝失敗解決方案
1.卸載重新安裝gem
卸載gem sudo gem uninstall --all
安裝gem sudo gem install cocoapods
如果碰到安裝失敗就修改一下安裝路徑,再進行安裝即可。
mkdir -p $HOME/Software/ruby
export GEM_HOME=$HOME/Software/ruby
gem install cocoapods
如果碰到安裝失敗,也可以這樣操作(指定安裝目錄)
sudo gem install -n /usr/local/bin cocoapods
2.更新gem
更新gem sudo gem update --system
四、cocoa pods命令
4.1為項目初始化pod
pod init
4.2為項目安裝pod
pod install 直接從網(wǎng)絡下載
pod install --no-repo-update 先從本地加載,沒有就在網(wǎng)絡加載(速度快)
4.3更新第三方庫 和 新添加第三方庫
pod update
4.4搜索第三方插件
pod search xxx
4.5查看本地存在的第三方庫
pod cache list
五、iOS項目配置cocoa pods
1.命令行進入到項目文件夾中
2.執(zhí)行pod init 會生成 Podfile 文件
3.xcode 打開 Podfile 文件
4.配置自己想要的第三方類庫即可
5.配置完成后執(zhí)行 pod install 進行安裝
6.項目中多了.xcworkspace文件,打開這個文件即可。
7.添加新的第三方或者更新第三方,修改Podfile文件,執(zhí)行pod update。
六、配置第三方庫
第三方庫逗號后邊是版本,不寫默認當前最高版本
platform :ios, '8.0'
pod 'AFNetworking','~> 2.6.1'
pod 'SDWebImage', '~> 3.7.3'
pod 'MMDrawerController'
7.pod 命令
7.1pod幫助指令
? ~ pod --help
Usage:
$ pod COMMAND
CocoaPods, the Cocoa library package manager.
Commands: pod的所有子命令
+ cache Manipulate the CocoaPods cache
+ init Generate a Podfile for the current directory.
+ install Install project dependencies to Podfile.lock versions
+ ipc Inter-process communication
+ lib Develop pods
+ list List pods
+ outdated Show outdated project dependencies
+ plugins Show available CocoaPods plugins
+ repo Manage spec-repositories
+ search Search for pods.
+ setup Setup the CocoaPods environment
+ spec Manage pod specs
+ trunk Interact with the CocoaPods API (e.g. publishing new specs)
+ try Try a Pod!
+ update Update outdated project dependencies and create new
Podfile.lock
Options: 選項
--silent Show nothing
--version Show the version of the tool
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
7.2pod子命令的幫助指令
? ~ pod update --help
Usage:
$ pod update [POD_NAMES ...]
Updates the Pods identified by the specified `POD_NAMES`. If no
`POD_NAMES` are specified it updates all the Pods ignoring the contents of
the Podfile.lock. This command is reserved to the update of dependencies
and pod install should be used to install changes to the Podfile.
Options: 選項
--project-directory=/project/dir/ The path to the root of the project
directory
--no-clean Leave SCM dirs like `.git` and `.svn`
intact after downloading
--no-integrate Skip integration of the Pods libraries
in the Xcode project(s)
--no-repo-update Skip running `pod repo update` before
install
--silent Show nothing
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
8.pod-Xcode使用
1.下載
1.1github 下載地址:
https://github.com/CocoaPods/Xcodeproj
1.2Alcatraz 中搜索 Cocoapods
1.3安裝插件
8.1為項目初始化pod

8.2填寫第三方庫

8.3為項目安裝pod

8.4安裝完成通過pod打開項目

8.5修改pod增刪第三方庫

8.6更新pod庫
