CocoaPods安装及出现的问题总结

Cocopod 是iOS开发中常用的第三方管理工具,通过CocoaPods,我们可以将第三方的依赖库统一管理起来,配置和更新只需要通过简单的几行命令即可完成,大大的提高了实际开发中的工作效率,掌握CocoaPods的使用是必不可少的基本技能了。

安装CocoaPods

1.安装前先升级Ruby环境


$sudo gem update —system

由于墙的原因会导致这一步非常缓慢,可以用淘宝的Ruby镜像来访问该网站


$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

查看是否更换成功:


gem sources -l

安装Cocoapods

sudo gem install cocoapods

这个时候会提示你输入密码

输入后开始安装...

安装成功后 查看版本

$ pod --version

使用CocoaPods

搜索目标库


$ pod search 库名  

创建Podfile


$ cd /项目文件

touch Podfile    //创建Podfile

创建成功后会在目录文件夹看到

编辑Podfile


$ vim Podfile

将搜索出来的库,拷贝进去
配置如下图:

设置

具体参考:cocoapods

platform :ios, ‘7.0’ //支持的最低版本
inhibit_all_warnings! //去除第三方的警告
use_frameworks! //修改引入方式,加了这句引入使用#import ” ” ; 未加使用#import < >

执行安装/更新

pod install

pod update

CocoaPods 实现快速更新

不检查CocoaPods specs更新

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

升级CocoaPods

1.添加镜像
$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
$ gem sources -l

2.升级 gem
查看gem gem --version
sudo gem update --system

1-2这个和安装流程差不多,不再重复

3.升级cocopod
sudo gem install -n /usr/local/bin cocoapods --pre


4.设置pod 仓库
pod setup

5.查看版本
pod --version

CocoaPods 使用中的一些问题

CocoaPods 搜索不到最新的版本库

1.cocoapods的版本过低

2.还没有更新本地仓库

按照上述更新cocoapods即可!

github上项目下载打开出错

diff: /../Podfile.lock: No such file or directory  
diff: Manifest.lock: No such file or directory   
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.`

1.关闭当前的工作空间,删除掉文件夹中的workspace
2.然后重新pod install。
3.install完成之后,通过workspace打开工作空间,clean+build即可:

rm -rf MyProject.xcworkspace  
pod install


多个xcode出现问题

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

那么你的命令行就要修改一下:

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

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

更多请点击个人博客

你可能感兴趣的:(CocoaPods安装及出现的问题总结)