IOS启程
— 配制CocoaPods来管理第三方类库
Mac OSX 10.11 之后
1 CocoaPods
CocoaPods应该是iOS最常用最有名的类库管理工具了,也就是说,在IOS开发过程中会用到许多其他类库使用CocoaPods可以很方便的来管理开发中使用到的类库
2 Ruby安装CocoaPods
Ruby 是一种开源的面向对象程序设计的服务器端脚本语言
mac 下自带ruby运行环境
查看 ruby的版本信息
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
2.1 替换Ruby的默认源
$ gem sources --remove https://rubygems.org/
//等有反应之后再敲入以下命令
$ gem sources -a https://ruby.taobao.org/
验证是否替换成功
$ gem sources -l
//输出
192:~ androidlongs$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
https://gems.ruby-china.org/
//移除地址
$ gem sources --remove https://gems.ruby-china.org/
2.2 更新Mac 的Gem,Gem是管理Ruby库和程序的标准包
sudo gem update -n /usr/local/bin —system
可能遇到的错误一
Library/Ruby/Site/2.0.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
2.3 完成安装CocoaPods
sudo gem install -n /usr/local/bin cocoapods
3 使用CocoaPods来添加第三方库
3.1 CocoaPods查找类库
pod search + 库名
如 pod search AFNetworking
将会输出搜索出来的 关于 AFNetworking 的相关版本信息
其中 pod ‘AFNetworking’, ‘~> 3.1.0’ 就是我们在使用 CocoaPods 配制类库中使用到的信息
-> AFNetworking (3.1.0)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 3.1.0'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3, 3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1,
2.6.0, 2.5.4, 2.5.3, 2.5.2, 2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3,
2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0,
1.0RC3, 1.0RC2, 1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
- Subspecs:
- AFNetworking/Serialization (3.1.0)
- AFNetworking/Security (3.1.0)
- AFNetworking/Reachability (3.1.0)
- AFNetworking/NSURLSession (3.1.0)
- AFNetworking/UIKit (3.1.0)
-> AFNetworking+AutoRetry (0.0.5)
Auto Retries for AFNetworking requests
pod 'AFNetworking+AutoRetry', '~> 0.0.5'
- Homepage: https://github.com/shaioz/AFNetworking-AutoRetry
- Source: https://github.com/shaioz/AFNetworking-AutoRetry.git
- Versions: 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]
:
3.2 找到项目文件夹 创建并编辑Podfile文件(可以终端操作,也可以直接手动操作)
$ pod init
编辑Podfile文件
//也可以直接使用文本编辑器打开
$ vi Podfile
弹出的窗口中
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target '名称' do
end
点击 i 进入编辑模式
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target '名称' do
pod 'AFNetworking', '~> 3.1.0'
end
然后输入 esc 退出编辑模式 :wq 保存退出
3.3 安装
$ pod install
安装完成后,项目目录结构
常用的三方类库
pod 'AFNetworking', '~> 3.1.0'
pod 'SDWebImage', '~> 4.0.0'
pod 'Masonry', '~> 1.0.2'
pod 'YYKit', '~> 1.0.9'
pod 'MJExtension', '~> 3.0.13'
pod 'SDWebImage', '~> 4.0.0'
pod 'MJRefresh', '~> 3.1.12'
pod 'JSONModel', '~> 1.7.0'
pod 'mob_smssdk'
pod 'FMDB', '~> 2.7.2'
#pod 'KeyboardToolBar', '~> 2.0.1'
#高德地图
pod 'AMapLocation', '~> 2.6.0'
pod 'AMapSearch'
pod 'AMap3DMap'