第三方cocoaPods管理工具的安装步骤

来源:互联网 发布:玲珑醉梦网络剧 编辑:程序博客网 时间:2024/05/22 00:17
第一步:ruby环境的搭建(更新)
更新语句:sudo gem update --system

1.验证当前的Ruby资源,如果不能翻墙,就继续
gem sources -l

2.移除现有Ruby默认源
gem sources -r https://rubygems.org/

3. 使用新的源,利用淘宝的ruby镜像访问(推荐)
gem sources -a https://ruby.taobao.org/

4.验证新源是否替换成功
gem sources -l

5.更新
sudo gem update --system

提示解析:
Latest version currently installed. Aborting.//已经是最新版
一大串代码+ RubyGems system software updated //更新成功

问题: ERROR:  While executing gem ... (OpenSSL::SSL::SSLError)
    SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A
解决方案:因为现有的Ruby源网址,访问不了,SSL协议不支持
1.先移除现有的Ruby源网址
gem sources -r https://rubygems.org/
2.前者是将https给成http来让mac系统访问,后者是利用淘宝的ruby镜像访问(推荐后者)
gem sources -a http://rubygems.org/ 或者 gem sources -a https://ruby.taobao.org/  输入y
3.验证新源是否替换成功 http://rubygems.org 或 https://ruby.taobao.org/
gem sources -l
4.开始更新
sudo gem update --system

问题: ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
解决方案:权限问题  更新时   sudo gem update —system  记得不要落了sudo

第二步:安装CocoaPods
第一步:sudo gem install cocoapods
第二步:pod setup
//注意:pod setup在执行时,会输出Setting up CocoaPods master repo,会等待很长时间,可以使用
cd ~/.cocoapods进入此目录下,然后用du -sh *来查看下载进度
//下载成功
CocoaPods 1.0.0.beta.6 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Setup completed

问题:ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
解决方案:sudo gem install -n /usr/local/bin cocoapods
问题2:
[!] /usr/bin/git clonehttps://github.com/CocoaPods/Specs.git master --depth=1

xcrun: error: active developer path ("/Volumes/刘文学/Xcode.app/Contents/Developer") does not exist, use `xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools (or see `man xcode-select`)
解决方案: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
再重新输入语句:pod setup

第三步:更新gem
sudo gem update --system
//一般情况下,安装CocoaPods时就会顺便更新

//提示解析
Latest version currently installed. Aborting.////已经是最新版

第四步:CocoaPods的使用
1.查询想要管理的第三方库,看看有没有
pod search 第三方库名  例:pod search MBProgressHud

//有用数据
-> MBProgressHUD (0.9.2)
   An iOS activity indicator view.
   pod 'MBProgressHUD', '~> 0.9.2’    //此行为关键
   - Homepage: http://www.bukovinski.com
   - Source:   https://github.com/matej/MBProgressHUD.git
   - Versions: 0.9.2, 0.9.1, 0.9, 0.8, 0.7, 0.6, 0.5 [master repo]

2.创建一个新工程,并进入工程文件夹
cd + 工程文件夹路径(直接将文件拖进控制器)

3.在工程文件夹中创建Podfile文件夹
vim Podfile

4.点击键盘的 i 键进入输入状态,并输入
platform:ios,'9.2'
pod 'MBProgressHUD','~> 0.9.2’  //第一步查询到的

5.按 Esc 退出输入状态,然后输入  :wq  回到终端命令

6.下载类库 pod update

7.进入工程使用第三方

#import <MBProgressHUD.h>
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"正在加载";
0 0
原创粉丝点击