欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iOS开发之cocoapods安装和使用

程序员文章站 2024-03-20 22:32:04
...

本文介绍了cocoapods的安装和使用过程.

一.配置cocoapods

1.删除源(这个系统自带的不好用)
$ sudo gem sources -r https://rubygems.org/

2.添加源(使用淘宝的镜像,记住要用https)
(淘宝的镜像不更新了,建议以后使用https://gems.ruby-china.org/记录于2017.5.4)
$ sudo gem sources -a https://ruby.taobao.org/

3.查看是否使用的是淘宝镜像
$ gem sources -l

4.安装 cocoapods
$ sudo gem install cocoapods

注意:在执行sudo gem install cocoapods命令时,出现错误:Error installing cocoapods:activesupport requires Ruby version >= 2.2.0,表示要安装ruby大于等于2.2.0的版本(这里安装ruby2.3.0的版本).

5.查看ruby当前版本
$ ruby -v (当前版本是2.0.0)

注意:先安装rvm,通过rvm去安装2.3.0的ruby.

6.安装 rvm
rvm:ruby Version Manager,ruby版本管理器,包括ruby的版本管理和Gem库管理(gemset)
$ curl -L get.rvm.io | bash -s stable (等待一段时间后便成功安装 rvm)

7.查询rvm的当前版本
$ rvm -v

8.安装ruby 2.3.0
$ rvm install 2.3.0

9.再次查看ruby当前版本
$ ruby -v (版本为2.3.0)

10.再次安装cocoapods
$ sudo gem install cocoapods

注意:出现Setting up CocoaPods master repo,说明Cocoapods在将它的信息下载到~/.cocoapods路径中;cd 到该目录中,用du -sh *命令来查看文件大小,每隔几分钟查看一次,这个目录最终大小是700多M,就表示下载完成了.

11.进入~/.cocoapods文件目录中
$ cd ~/.cocoapods

12.查看文件大小
$ du -sh *

13.安装成功之后,查看是否是最新版本(目前最新版本是1.0.1)
$ pod –version

二.将第三方框架集成到项目中

1.进入项目文件的目录中(BYSliderChooseView是项目文件名)
$ cd /Users/lby/Desktop/GitHub/BYSliderChooseView

2.初始化一个podfile文件(在对应路径中创建podfile文件)
$ pod init

3.搜索你需要用到的第三方框架(如:SDWebImage)找到之后,复制 pod ‘SDWebImage’ 到podfile中,如果要指定版本号,就跟上版本号就行.
podsearchSDWebImage pod ‘SDWebImage’, ‘~> 4.1.0’

iOS开发之cocoapods安装和使用

podfile文件中代码如下:(platform指支持的最低版本,可以根据项目情况调整,BYSliderChooseView是项目名称)

platform :ios, ‘9.0’
target ‘BYSliderChooseView’ do
pod ‘SDWebImage’, ‘~> 4.1.0’
end

4.安装$ pod install (如果是更新使用:pod update –repo-no-update)
完成之后有个提示:Please close any current Xcode sessions and use 'BYSliderChooseView.xcworkspace' for this project from now on.


以上是之前安装和使用的过程,而这次做了一个尝试.(2017MacPro Without TouchBar)
1.ruby版本不变,仍旧是2.0.0版本.
2.使用系统自带的源.
3.已经*.
所以,在什么都不改变的情况下,直接执行
sudo gem install cocoapods命令,没有报错,有一系列执行结果,运行完成,再执行pod setup,出现Setting up CocoaPods master repo,等待,如果看到`Setup completed,就安装完成了.

附上操作内容:

Last login: Thu Aug 24 12:52:58 on ttys000
localhost:~ lby$ ruby -v(执行代码)
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
localhost:~ lby$ sudo gem install cocoapods(执行代码)
Password:(执行代码)
Fetching: i18n-0.8.6.gem (100%)
Successfully installed i18n-0.8.6
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.3.gem (100%)
Successfully installed tzinfo-1.2.3
Fetching: minitest-5.10.3.gem (100%)
Successfully installed minitest-5.10.3
Fetching: activesupport-4.2.9.gem (100%)
Successfully installed activesupport-4.2.9
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.3.1.gem (100%)
Successfully installed cocoapods-core-1.3.1
Fetching: claide-1.0.2.gem (100%)
Successfully installed claide-1.0.2
Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.1
Fetching: cocoapods-downloader-1.1.3.gem (100%)
Successfully installed cocoapods-downloader-1.1.3
Fetching: cocoapods-plugins-1.0.0.gem (100%)
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-search-1.0.0.gem (100%)
Successfully installed cocoapods-search-1.0.0
Fetching: cocoapods-stats-1.0.0.gem (100%)
Successfully installed cocoapods-stats-1.0.0
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-1.2.0.gem (100%)
Successfully installed cocoapods-trunk-1.2.0
Fetching: cocoapods-try-1.1.0.gem (100%)
Successfully installed cocoapods-try-1.1.0
Fetching: molinillo-0.5.7.gem (100%)
Successfully installed molinillo-0.5.7
Fetching: CFPropertyList-2.3.5.gem (100%)
Successfully installed CFPropertyList-2.3.5
Fetching: colored2-3.1.2.gem (100%)
Successfully installed colored2-3.1.2
Fetching: nanaimo-0.2.3.gem (100%)
Successfully installed nanaimo-0.2.3
Fetching: xcodeproj-1.5.1.gem (100%)
Successfully installed xcodeproj-1.5.1
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: fourflusher-2.0.1.gem (100%)
Successfully installed fourflusher-2.0.1
Fetching: gh_inspector-1.0.3.gem (100%)
Successfully installed gh_inspector-1.0.3
Fetching: ruby-macho-1.1.0.gem (100%)
Successfully installed ruby-macho-1.1.0
Fetching: cocoapods-1.3.1.gem (100%)
Successfully installed cocoapods-1.3.1
Parsing documentation for i18n-0.8.6
Installing ri documentation for i18n-0.8.6
Parsing documentation for thread_safe-0.3.6
Installing ri documentation for thread_safe-0.3.6
Parsing documentation for tzinfo-1.2.3
Installing ri documentation for tzinfo-1.2.3
Parsing documentation for minitest-5.10.3
Installing ri documentation for minitest-5.10.3
Parsing documentation for activesupport-4.2.9
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.9
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-1.3.1
Installing ri documentation for cocoapods-core-1.3.1
Parsing documentation for claide-1.0.2
Installing ri documentation for claide-1.0.2
Parsing documentation for cocoapods-deintegrate-1.0.1
Installing ri documentation for cocoapods-deintegrate-1.0.1
Parsing documentation for cocoapods-downloader-1.1.3
Installing ri documentation for cocoapods-downloader-1.1.3
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.0
Installing ri documentation for cocoapods-search-1.0.0
Parsing documentation for cocoapods-stats-1.0.0
Installing ri documentation for cocoapods-stats-1.0.0
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-1.2.0
Installing ri documentation for cocoapods-trunk-1.2.0
Parsing documentation for cocoapods-try-1.1.0
Installing ri documentation for cocoapods-try-1.1.0
Parsing documentation for molinillo-0.5.7
Installing ri documentation for molinillo-0.5.7
Parsing documentation for CFPropertyList-2.3.5
Installing ri documentation for CFPropertyList-2.3.5
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for nanaimo-0.2.3
Installing ri documentation for nanaimo-0.2.3
Parsing documentation for xcodeproj-1.5.1
Installing ri documentation for xcodeproj-1.5.1
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.0.1
Installing ri documentation for fourflusher-2.0.1
Parsing documentation for gh_inspector-1.0.3
Installing ri documentation for gh_inspector-1.0.3
Parsing documentation for ruby-macho-1.1.0
Installing ri documentation for ruby-macho-1.1.0
Parsing documentation for cocoapods-1.3.1
Installing ri documentation for cocoapods-1.3.1
27 gems installed
localhost:~ lby$ cd ~/.cocoapods(执行代码)
-bash: cd: /Users/lby/.cocoapods: No such file or directory
localhost:~ lby$ gem sources -l(执行代码)
*** CURRENT SOURCES ***

[https://rubygems.org/](https://rubygems.org/)
localhost:~ lby$ pod setup(执行代码)
Setting up CocoaPods master repo
  $ /usr/bin/git clone [https://github.com/CocoaPods/Specs.git](https://github.com/CocoaPods/Specs.git) master --progress
  Cloning into 'master'...
  remote: Counting objects: 1483411, done.       
  remote: Compressing objects: 100% (316/316), done.       
  remote: Total 1483411 (delta 169), reused 230 (delta 96), pack-reused 1482979       
  Receiving objects: 100% (1483411/1483411), 419.73 MiB | 1.35 MiB/s, done.
  Resolving deltas: 100% (768999/768999), done.
  Checking out files: 100% (176707/176707), done.
Setup completed
localhost:~ lby$ cd ~/.cocoapods(执行代码)
localhost:.cocoapods lby$ ls(执行代码)
repos
localhost:.cocoapods lby$

简书

iOS开发之cocoapods安装和使用

个人博客

iOS开发之cocoapods安装和使用