還在用老版本的ccoaPods,安裝三方庫時,會報錯 :
[!] Invalid `Podfile` file: [!] The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead..
所以得升級cocoaPods到1.2.1最新版
安裝源:
1、查看ruby源
gem sources -l
2、移除掉原有的源
gem sources --remove https://rubygems.org/
3、添加國內最新的源。ruby-china
gem sources -a https://gems.ruby-china.org
4、檢查是否添加成功
gem sources -l
5、安裝cocoapods
sudo gem install -n /usr/local/bin cocoapods
6、安裝完成后查看pod版本
pod --version
7、更新Podspec索引文件,創建本地索引庫(這里要多等一會兒)
pod setup
8、進入項目目錄
cd ~
9.創建Podfile文件 (編寫Podfile文件也是一個注意點,主要一點是項目有多個target)
情況一:多個target公用相同庫,還可以添加額外的不同第三方庫.
# -*- coding: UTF-8 -*- source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' # ruby語法 # target數組 如果有新的target直接加入該數組 targetsArray = ['targetName1', 'targetName2', 'targetName3', 'targetName4', 'targetName5'] # 循環 targetsArray.each do |t| target t do pod 'MJRefresh', '~> 1.4.6' pod 'Masonry', '~> 0.6.1' end end
情況二:當項目只有一個target
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' target 'targetName1' do pod 'MJRefresh', '~> 1.4.6' pod 'Masonry', '~> 0.6.1' end
情況三:不同target依賴庫
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' target 'targetName1' do pod 'MJRefresh', '~> 1.4.6' pod 'Masonry', '~> 0.6.1' end target 'targetName2' do pod 'MJRefresh', '~> 1.4.6' pod 'Masonry', '~> 0.6.1' pod 'AFNetworking', '~> 3.0' end
參考來自:
http://www.cnblogs.com/Crazy-D/p/6421611.html http://www.jianshu.com/p/5d29bc212273