您的位置:首页 > 编程语言 > Ruby

2017版cocoapods安装及使用和注意事项

2017-06-26 22:39 309 查看
A.安装ruby
a 查看ruby版本
ruby -v
b.如果版本低升级。

1.先安装rvm。Ruby Version Manager,Ruby版本管理器,包括Ruby的版本管理和Gem库管理(gemset)。
curl -L https://get.rvm.io | bash -s stable
2.载入rvm环境
source ~/.rvm/scripts/rvm
3.用rvm 安装ruby环境
rvm install 2.3.0
4.设置为默认版本
rvm use
2.2.4 --default
5.安装rails
gem install rails

补充命令
如果要删除ruby版本,先用list命令。
▪ rvm list 查看已安装ruby
▪ rvm list known 列出ruby可安装版本信息
▪ rvm remove 2.2.2 卸载一个已安装的ruby版本
▪ gem source 查看已有源
▪ gem sources -a
http://ruby.taobao.org把源切换至淘宝镜像服务器

B.安装CocoaPods
a.检查ruby源
gem sources -l
推荐官方的:https://gems.ruby-china.org https://ruby.taobao.org/   淘宝源 http://rubygems-china.oss.aliyuncs.com 阿里云源
b.添加ruby镜像源
gem sources -a https://gems.ruby-china.org

c.安装
sudo gem install cocoapods
d.安装结束后,执行命令
pod setup

C.使用CocoaPods

a.新建一个项目,名字CocoaPodsTest
b.终端中,cd到项目总目录(注意:包含CocoaPodsTest文件夹、CocoaPodsTest.xcodeproj的那个总目录)
c.建立Podfile(配置文件)
1.终端输入 vim Podfile
2.键盘输入 i,进入编辑模式,
3.输入最新的platform和最新的第三方的名称和版本.参考如下格式

platform :ios, '9.0'
target 'JinXinHospital' do
  pod 'AFNetworking','~> 3.1.0'
end

4.按Esc,并且输入“
:”号进入vim命令模式,然后在冒号后边输入wq
注意:键盘输入 :后,才能输入wq。回车后发现PodTest项目总目录中多个Podfile文件
5.输入 pod install,
6.安装好各个第三方之后,打开后缀名为.xcworkspace的文件,即可使用
d.注意:
1)项目存在多个Target的时候,需要配置Podfile文件来支持新增加的Target,否则只支持项目默认建立时生成的Target:
link_with 'Test', 'Second'  
platform :ios  
pod 'AFNetworking', '~> 2.0'  

2)项目有不同依赖库时
platform :ios  
target :'Test' do  
pod 'Reachability'  
pod 'SBJson'     
pod 'AFNetworking'   
end    
    
target :'Second' do  
pod 'OpenUDID'   
end 
参考链接博客:http://blog.csdn.net/daiyelang/article/details/51766916

D.使用CocoaPod问题

a.fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': SSLRead()
遇到这种问题的话,可以手动去克隆一份到repos目录下面。
步骤
1.通过finder的前往文件夹进行查看       ~/.cocoapods/repos
2.通过终端,进入到   ~/.cocoapods/repos
3.然后通过   git clone
https://github.com/CocoaPods/Specs.git  

还有其他问题的话,先看看是不是rubygem镜像源是不是被墙了,可以切换镜像源。

甚至,如果最终实在没办法,找到一个安装好了cocoapods的Mac电脑,到他的~/.cocoapods/repos目录下面拷贝出master文件到自己的Mac上的相应位置。 

参考链接:http://www.jianshu.com/p/b64b4fd08d3c

b.error: RPC failed; curl 18 transfer closed with outstanding read data remaining
参考链接: http://blog.csdn.net/wangyanchang21/article/details/51437934 可能是因为有多个Xcode:
xcode-select —print-path 查看Xcode安装路径

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

c.unable to access 'https://github.com/CocoaPods/Specs.git/': SSLRead() return error -9806
网络不好的原因

d.error: RPC failed; curl 56 SSLRead() return error -36 | 547.00 KiB/s 
参考链接:  http://blog.csdn.net/wm9028/article/details/51840759
e.Invalid `Podfile` file: undefined method `Pod' for #<Pod::Podfile:0x007fdb9530cd70>
cocoapod需要更新
运行 sudo gem install cocoapods 进行更新 cocoapods
更新完后再运行 pod update

f.Unable to find a pod with name, author, summary, or description matching `AFNetworking`
 先删除:rm -rf ~/.cocoapods
 再pod setup
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ruby cocoapods