CocoaPods管理第三方,从安装到使用

一,引入CocoaPods:

(1).检测有没有引入淘宝镜像:gem sources -l

(2).删除ruby镜像

         gem sources —remove https://rubygems.org/  

         //如果删不掉

         sudo gem sources —remove https://rubygems.org/

(3).添加taobao镜像

        gem sources -a https://ruby.taobao.org/

(4).安装cocoapods

        gem install cocoapods

到这里就已经安装成功了。下面就开始使用了~

二,CocoaPods导入第三方类(如:AFN)步骤:

1. cd +文件夹

2.pod  search afnetworking

{如果没有结果,报错:“[!] Unable to find a pod with name, author, summary, or descriptionmatching `SSKeychain`”

则直接rm ~/Library/Caches/CocoaPods/search_index.json即可,然后重新pod  search afnetworking就出来了}

3.vim  podfile ,在文件里面粘贴版本

4.退出ESC  :wq

5.pod  install

注意:

最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动,原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少。加参数的命令如下:

pod install --verbose --no-repo-update

pod update --verbose --no-repo-update

至此,你想要的第三方就已经导入到你的项目中了,就可以使用了。

 

三,更新第三方库

1.找到文件中的podfile文件,修改第三方库的版本号

2.更新:pod update --verbose --no-repo-update

 

四,异常情况处理:

(1)执行$pod setup 的时候报错:

[!] /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git master

Cloning into 'master'...

error: RPC failed; curl 56 SSLRead() return error -36

fatal: The remote end hung up unexpectedly

fatal: early EOF

fatal: index-pack failed

解决方案: 
打开终端命令行,输入一下命令:

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

并不一定是这行代码,要根据自己的情况,来修改这个命令行 
1、当然一个xcode执行这行肯定没问题 
单个xcode 
2、也许你是多个xcode 
安装多个xcode 
那么你的命令行就要修改一下:

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

根据你默认的xcode来修改在/Applications/和/Contents/Developer中间的app的名字,如果你默认的是Xcode x.x.x.app,中间就要替换掉哟!

ps:问题还存在,把xcode全部卸载,只装一个最新的。

3、最简便的方式是: 
先在终端输入”sudo xcode-select -switch “,然后,打开Xcode—>右键显示包内容,找到Developer文件夹拖到终端里面

PS:一些xcode-select的命令的使用:

xcode-select [-help] xcode-select [-switch xcode_folder_path] xcode-select [-print-path] xcode-select [-version]

例如: 
打印当前xcode的路径

xcode-select --print-path

输出:

/Applications/Xcode.app/Contents/Developer

 

(2)   pod search afnetworking的时候,报错

[!] Unable to find a pod with name, author, summary, or description matching `afnetworking`

解决方法:

  1. 删除~/Library/Caches/CocoaPods目录下的search_index.json文件

    • pod setup成功后,依然不能pod search,是因为之前你执行pod search生成了search_index.json,此时需要删掉。
    • 终端输入:rm ~/Library/Caches/CocoaPods/search_index.json
    • 删除成功后,再执行pod search
  2. 执行pod search

    • 终端输入:pod search afnetworking(不区分大小写)
    • 输出:Creating search index for spec repo 'master'.. Done!,稍等片刻······就会出现所有带有afnetworking字段的类库。

 

原文地址:https://www.cnblogs.com/wenqian/p/6117987.html