#cocoapods安裝
-移除現(xiàn)有Ruby默認源
-sudo gem sources --remove https://rubygems.org/
-使用新的源
-sudo gem sources -a https://ruby.taobao.org
-驗證新源是否替換成功
- gem sources -l
-更新gem
- sudo gem update --system
-安裝CocoaPods:
-安裝:
- OS X EL Capitan之前: sudo gem install cocoapods
- OS X EL Capitansudo之后:sudo gem install -n /usr/local/bin cocoapods
-設(shè)置
-pod setup:建議使用這個命令設(shè)置,下面兩個換源安裝命令好像無法正常使用了
-這個命令是從國外的網(wǎng)站更新庫,我們可以換成國內(nèi)的網(wǎng)站
- pod repo remove master
- pod repo add master https://gitcafe.com/akuandev/Specs.git
-或者把元換成http://git.oschina.net/akuandev/Specs.git
-更新
- pod repo update
#cocoapods更新第三方庫
-如果需要更新cocapods中的第三方庫,就不需要pod setup了,只需要pod repo update更新就可以了
#cocoapods使用
-新建工程,并在終端用cd指令到項目的文件中
- pod search :搜索第三方庫,可以查看
-新建文件vim “Podfile”,
- vim Podfile
-寫入以下內(nèi)容并保存小提示:(終端vim文件按i可編輯,esc退出編輯,:wq可保存退出)
-在項目根目錄下使用pod init創(chuàng)建一個Podfile
- platform :ios, '8.0' :說明平臺與當(dāng)前ios系統(tǒng)版本,最好寫8.0以上的
- use_frameworks!
- target 'MyApp' do :項目target的名字:MyApp是target名字
- pod 'AFNetworking', '~> 2.6'第三方庫一定要在cocoapods上有的并且名字一樣
- pod 'ORStackView', '~> 3.0'
- pod 'SwiftyJSON', '~> 2.3'
- end
-安裝第三方庫:命令終端
- pod install
-導(dǎo)入第三方框架
-`#import `
-退出終端
#常見錯誤
-以下是我用以前的安裝流程安裝時出現(xiàn)的一些錯誤,終端cocoapods下載bug調(diào)試:
-錯誤1:
- Error fetching http://ruby.taobao.org/:bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
-解決方案:把安裝流程中$gem sources -a http://ruby.taobao.org/---改為----> $gem sources -a https://ruby.taobao.org/
-錯誤2:
- ERROR:While executing gem ... (Errno::EPERM)Operation not permitted - /usr/bin/pod
-解決方案:蘋果系統(tǒng)升級OS X EL Capitan后會出現(xiàn)的插件錯誤,將安裝流程4.安裝CocoaPods的(1)sudo gem install cocoapods ——>改為sudo gem install -n /usr/local/bin cocoapods
-錯誤3:
-[!]Unable to satisfy the following requirements: - 'AVOSCloud (~> 3.1.6.3)' required by 'Podfile' Specs satisfying the 'AVOSCloud '(~> 3.1.6.3)' dependency were found, but they required a higher minimum deployment target.
-解決方案:安裝流程:Podfile文件中platform:ios, ‘6.0’后邊的6.0是平臺版本號,一定要加
-錯誤4:
- Invalid 'Podfile' file: undefined local variable or method ':ios';for #
-解決方案:Podfile文本中處出現(xiàn)了中文標(biāo)識符,修改掉就可以了
-錯誤5:The dependency ‘SDWebImage’ is not used in any concrete target
-解決方案:出這個錯是告訴我們我們所用的庫沒有指定target,`cocoapods`不知道用在哪里,所以就給報錯了`cocoapods測試`是我的項目里的target
-解決方法1:
- platform :ios, '8.0'
- target 'cocoapods測試' do
- pod 'AFNetworking', '~> 2.6'
- pod 'ORStackView', '~> 3.0'
- pod 'SwiftyJSON', '~> 2.3'
- end
-解決方法2:
- platform :ios, '8.0'
- def pods
- pod 'AFNetworking', '~> 2.6'
- pod 'ORStackView', '~> 3.0'
- pod 'SwiftyJSON', '~> 2.3'
- end
- target 'MyApp' do
- pods
- end