Cocoapods的安装与基本使用

Cocoapods的安装和升级都可以这么干,快速有效!^_^

0、更新gem

sudo gem update –system

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公用相同库,还可以添加额外的不同第三方库.

source ‘https://github.com/CocoaPods/Specs.git'
platform :ios, ‘8.0’
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