打开 终端
1. 移除系统自带的 因为该rub已经被和谐了 使用ruby.taobao.org
MCJ:~ MCJ$ sudo gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
MCJ:~ MCJ$ sudo gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
MCJ:~ MCJ$ sudo gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
2. 安装 cocoapods(接着刚才的写 sudo gem install cocoapods 系统会自动帮你下载cocoapods)
MCJ:~ MCJ$ sudo gem install cocoapods
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.8.3.gem (100%)
Successfully installed minitest-5.8.3
Fetching: activesupport-4.2.5.gem (100%)
Successfully installed activesupport-4.2.5
Fetching: nap-1.0.0.gem (100%)
Successfully installed nap-1.0.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.39.0.gem (100%)
Successfully installed cocoapods-core-0.39.0
Fetching: claide-0.9.1.gem (100%)
Successfully installed claide-0.9.1
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: xcodeproj-0.28.2.gem (100%)
Successfully installed xcodeproj-0.28.2
Fetching: cocoapods-downloader-0.9.3.gem (100%)
Successfully installed cocoapods-downloader-0.9.3
Fetching: cocoapods-plugins-0.4.2.gem (100%)
Successfully installed cocoapods-plugins-0.4.2
Fetching: cocoapods-search-0.1.0.gem (100%)
Successfully installed cocoapods-search-0.1.0
Fetching: cocoapods-stats-0.6.2.gem (100%)
Successfully installed cocoapods-stats-0.6.2
Fetching: cocoapods-try-0.5.1.gem (100%)
Successfully installed cocoapods-try-0.5.1
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-0.6.4.gem (100%)
Successfully installed cocoapods-trunk-0.6.4
Fetching: molinillo-0.4.0.gem (100%)
Successfully installed molinillo-0.4.0
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: cocoapods-0.39.0.gem (100%)
Successfully installed cocoapods-0.39.0
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for minitest-5.8.3
Installing ri documentation for minitest-5.8.3
Parsing documentation for activesupport-4.2.5
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-4.2.5
Parsing documentation for nap-1.0.0
Installing ri documentation for nap-1.0.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-0.39.0
Installing ri documentation for cocoapods-core-0.39.0
Parsing documentation for claide-0.9.1
Installing ri documentation for claide-0.9.1
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for xcodeproj-0.28.2
Installing ri documentation for xcodeproj-0.28.2
Parsing documentation for cocoapods-downloader-0.9.3
Installing ri documentation for cocoapods-downloader-0.9.3
Parsing documentation for cocoapods-plugins-0.4.2
Installing ri documentation for cocoapods-plugins-0.4.2
Parsing documentation for cocoapods-search-0.1.0
Installing ri documentation for cocoapods-search-0.1.0
Parsing documentation for cocoapods-stats-0.6.2
Installing ri documentation for cocoapods-stats-0.6.2
Parsing documentation for cocoapods-try-0.5.1
Installing ri documentation for cocoapods-try-0.5.1
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-0.6.4
Installing ri documentation for cocoapods-trunk-0.6.4
Parsing documentation for molinillo-0.4.0
Installing ri documentation for molinillo-0.4.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for cocoapods-0.39.0
Installing ri documentation for cocoapods-0.39.0
21 gems installed
3. 在我们项目文件的主文件路径创建一个Podfile文件
MCJ:~ MCJ$ cd /Users/qianfeng/Desktop/Test/CocoaPodsDemo
MCJ:CocoaPodsDemo MCJ$ touch Podfile
4. 打开我们创建的Podfile 文件写入我们想下载的第三库的名称和版本
5. 执行下载第三方库(这个需要一定时间 需要看网速)
MCJ:CocoaPodsDemo MCJ$ pod install --verbose --no-repo-update
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Using AFNetworking (2.6.3)
Using Reachability (3.0.0)
Using SBJson (4.0.2)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 3 dependencies from the Podfile and 3 total
pods installed.
这样就是下载成功 如果你想看看你Podfile文件的内容可以使用
MCJ:CocoaPodsDemo MCJ$ cat Podfile
pod 'Reachability', '~> 3.0.0'
pod 'SBJson', '~> 4.0.0'
pod 'AFNetworking', '~> 2.0'
6. 下载成功之后来到项目的文件 以后直接双击CocoaPodsDemo.xcworkspace 打开项目就可以编写的代码
打开项目的效果
7. 在项目里想使用哪个第三方直接导入头文件就行了
8. 如果想在cocoapods 添加新的第三方库
如果知道名字和版本只需要把 名称和版本添加到Podfile文件更新一下pod 就行了
MCJ:CocoaPodsDemo MCJ$ pod install
如果不知道 可以搜索 把搜索到得添加到Podfile文件 更新一下pod 就行了
MCJ:CocoaPodsDemo MCJ$ pod search SDWebimage