CocoaPods是什么?
1.说这么一个现场,如果要引用第三方类库是不是要把他拖进项目引用或者copy,如果第三方类库更新了,你是不是又要重新应用更新啊?答案是肯定的。
2.另外一种情况,如果项目过大,且项目中有很多相对独立的功能,分工到不同人的手中维护升级开发,最后整合项目(其实可把他们看作第三方类库),是不是也会遇到copy或者引用的问题。
以上两点会导致,遇到更改就要换代码换文件,如果你的项目就一个,可以很轻松换掉,如果是10个 ,100个....估计就该抱怨了,cocoapos一个链接就搞定了,可以很好提高效率,同时有利于分工协作。
今天把cocoapods安装过程总结分享给大家。
CocoaPods安装
第一步:安装CocoaPods之前,首先要在本地安装好Ruby环境。(ruby安装 https://ruby-china.org/wiki/install_ruby_guide)
安装ruby过程如下:
a.确保 已经安装xCode的Command Line Tools
b.打开终端:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install ruby
第二步: 当b步骤执行成功后,在终端输入:
sudo gem install cocoapods
发现没有反映,别急换个方法:
如果发现报:Could not find a valid gem 'cocoapods' (>= 0) in any repository 别急,这个问题说明是你的gem版本过旧了 (没有报错此步骤可以跳过)
在终端先输入:
sudo gem update --system
重新打开终端输入:
gem sources --remove https://rubygems.org/
会返回:
https://rubygems.org/ removed from sources
在输入:gem sources -a https://ruby.taobao.org/
会返回:
https://ruby.taobao.org/ added to sources
检测一下在终端输入:gem sources -l
得到如下:
*** CURRENT SOURCES ***
https://ruby.taobao.org/
为什么这么做?原因是国家的防火墙有点牛,猜的!第三步:再次输入:
sudo gem install cocoapods
等待几十秒会返回:
Fetching: multi_json-1.10.1.gem (100%)
Successfully installed multi_json-1.10.1
Fetching: activesupport-3.2.19.gem (100%)
Successfully installed activesupport-3.2.19
Fetching: nap-0.8.0.gem (100%)
Successfully installed nap-0.8.0
Fetching: json_pure-1.8.1.gem (100%)
Successfully installed json_pure-1.8.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.33.1.gem (100%)
Successfully installed cocoapods-core-0.33.1
Fetching: claide-0.6.1.gem (100%)
Successfully installed claide-0.6.1
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: xcodeproj-0.17.0.gem (100%)
Building native extensions. This could take a while...
[!] You are using the prebuilt binary version of the xcodeproj gem.
Successfully installed xcodeproj-0.17.0
Fetching: cocoapods-downloader-0.6.1.gem (100%)
Successfully installed cocoapods-downloader-0.6.1
Fetching: cocoapods-plugins-0.2.0.gem (100%)
Successfully installed cocoapods-plugins-0.2.0
Fetching: cocoapods-try-0.3.0.gem (100%)
Successfully installed cocoapods-try-0.3.0
Fetching: netrc-0.7.7.gem (100%)
Successfully installed netrc-0.7.7
Fetching: cocoapods-trunk-0.1.4.gem (100%)
Successfully installed cocoapods-trunk-0.1.4
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: open4-1.3.4.gem (100%)
Successfully installed open4-1.3.4
Fetching: cocoapods-0.33.1.gem (100%)
CHANGELOG:
## 0.33.1
##### Bug Fixes
* Fix `pod spec lint` for `json` podspecs.
[Fabio Pelosin][irrationalfab]
[#2157](https://github.com/CocoaPods/CocoaPods/issues/2157)
* Fixed downloader issues related to `json` podspecs.
[Fabio Pelosin][irrationalfab]
[#2158](https://github.com/CocoaPods/CocoaPods/issues/2158)
* Fixed `--no-ansi` flag in help banners.
[Fabio Pelosin][irrationalfab]
[#34](https://github.com/CocoaPods/CLAide/issues/34)
Successfully installed cocoapods-0.33.1
Parsing documentation for multi_json-1.10.1
Installing ri documentation for multi_json-1.10.1
Parsing documentation for activesupport-3.2.19
unable to convert "\x80" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-3.2.19
Parsing documentation for nap-0.8.0
Installing ri documentation for nap-0.8.0
Parsing documentation for json_pure-1.8.1
Installing ri documentation for json_pure-1.8.1
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-0.33.1
Installing ri documentation for cocoapods-core-0.33.1
Parsing documentation for claide-0.6.1
Installing ri documentation for claide-0.6.1
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for xcodeproj-0.17.0
Installing ri documentation for xcodeproj-0.17.0
Parsing documentation for cocoapods-downloader-0.6.1
Installing ri documentation for cocoapods-downloader-0.6.1
Parsing documentation for cocoapods-plugins-0.2.0
Installing ri documentation for cocoapods-plugins-0.2.0
Parsing documentation for cocoapods-try-0.3.0
Installing ri documentation for cocoapods-try-0.3.0
Parsing documentation for netrc-0.7.7
Installing ri documentation for netrc-0.7.7
Parsing documentation for cocoapods-trunk-0.1.4
Installing ri documentation for cocoapods-trunk-0.1.4
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for open4-1.3.4
Installing ri documentation for open4-1.3.4
Parsing documentation for cocoapods-0.33.1
Installing ri documentation for cocoapods-0.33.1
17 gems installed
我的终端:
CocoaPods使用
使用很简单如在终端输入:
pod search AFNetworking
结果返回:
Setting up CocoaPods master repo
嚓,知道吗?我等了足足半个小时。所以请内心等待.半小时之后返回:
Setup completed (read-only access)
-> AFNetworking (2.3.1)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 2.3.1'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 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]
- Sub specs:
- AFNetworking/Serialization (2.3.1)
- AFNetworking/Security (2.3.1)
- AFNetworking/Reachability (2.3.1)
- AFNetworking/NSURLConnection (2.3.1)
- AFNetworking/NSURLSession (2.3.1)
- AFNetworking/UIKit (2.3.1)
-> AFNetworking+AutoRetry (0.0.3)
Auto Retries for AFNetworking requests
pod 'AFNetworking+AutoRetry', '~> 0.0.3'
- Homepage: https://github.com/shaioz/AFNetworking-AutoRetry
- Source: https://github.com/shaioz/AFNetworking-AutoRetry.git
- Versions: 0.0.3, 0.0.2, 0.0.1 [master repo]
-> AFNetworking+streaming (0.5)
A very quick extension to AFNetworking that adds stream based parsing
pod 'AFNetworking+streaming', '~> 0.5'
- Homepage: https://github.com/deanWombourne/AFNetworking-streaming
- Source: https://github.com/deanWombourne/AFNetworking-streaming.git
- Versions: 0.5, 0.4, 0.3, 0.2, 0.1 [master repo]
- Sub specs:
- AFNetworking+streaming/Core (0.5)
- AFNetworking+streaming/Json (0.5)
-> AFNetworking-MUResponseSerializer (1.0.0)
Automatically serialize JSON response to your object model. It also works with
NSManagedObjects.
pod 'AFNetworking-MUResponseSerializer', '~> 1.0.0'
- Homepage: https://github.com/Ulianko/AFNetworking-MUResponseSerializer
- Source: https://github.com/Ulianko/AFNetworking-MUResponseSerializer.git
- Versions: 1.0.0 [master repo]
-> AFNetworking-RACExtensions (0.1.4)
AFNetworking-RACExtensions is a delightful extension to the AFNetworking classes for iOS
and Mac OS X.
pod 'AFNetworking-RACExtensions', '~> 0.1.4'
- Homepage: https://github.com/CodaFi/AFNetworking-RACExtensions
- Source: https://github.com/CodaFi/AFNetworking-RACExtensions.git
- Versions: 0.1.4, 0.1.2, 0.1.1, 0.0.1 [master repo]
-> AFNetworking-ReactiveCocoa (0.0.2)
Make AFNetworking reactive.
pod 'AFNetworking-ReactiveCocoa', '~> 0.0.2'
- Homepage: https://github.com/uasi/AFNetworking-ReactiveCocoa
- Source: https://github.com/uasi/AFNetworking-ReactiveCocoa.git
- Versions: 0.0.2, 0.0.1 [master repo]
-> AFNetworking-Synchronous (0.2.0)
Synchronous requests for AFNetworking
pod 'AFNetworking-Synchronous', '~> 0.2.0'
- Homepage: https://github.com/paulmelnikow/AFNetworking-Synchronous
- Source: https://github.com/paulmelnikow/AFNetworking-Synchronous.git
- Versions: 0.2.0, 0.1.0 [master repo]
-> AFNetworking2-RACExtensions (0.0.1)
AFNetworking-RACExtensions is a delightful extension to the AFNetworking classes for iOS
and Mac OS X.
pod 'AFNetworking2-RACExtensions', '~> 0.0.1'
- Homepage: https://github.com/knshiro/AFNetworking-RACExtensions
- Source: https://github.com/knshiro/AFNetworking-RACExtensions.git
- Versions: 0.0.1 [master repo]
-> CollectionUtils-AFNetworking (1.0.1)
CollectionUtils additions for AFNetworking.
pod 'CollectionUtils-AFNetworking', '~> 1.0.1'
- Homepage: https://github.com/kishikawakatsumi/CollectionUtils
- Source: https://github.com/kishikawakatsumi/CollectionUtils.git
- Versions: 1.0.1, 1.0.0 [master repo]
-> CollectionUtils-AFNetworking-1.3 (1.0.1)
CollectionUtils additions for AFNetworking 1.3.x.
pod 'CollectionUtils-AFNetworking-1.3', '~> 1.0.1'
- Homepage: https://github.com/kishikawakatsumi/CollectionUtils
- Source: https://github.com/kishikawakatsumi/CollectionUtils.git
- Versions: 1.0.1, 1.0.0 [master repo]