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

CocoaPods安装流程以及常见错误

2016-08-12 16:51 495 查看

一、 CocoaPods 安装流程

(1)CocoaPods的使用淘宝的Ruby镜像替换官方的ruby源,在终于输入命令

$ gem sources --remove https://rubygems.org/ $ gem sources -a https://ruby.taobao.org/ $ gem sources -l


如果结果为下面的样子,说明替换成功了。

***CURRENT SOURCES ***
 https://ruby.taobao.org/[/code] 

(2)升级gem,在终端输入命令

$ sudo gem update --system


接着会要求输入电脑密码,输入密码后回车,就开始升级了。如果看到下面这句话,说明升级成功了。

RubyGems system software updated


(3)安装CocoaPods,在终端输入命令

$ sudo gem install cocoapods


输入密码后开始安装。

二、CocoaPods的使用

(1)查找第三方库,在终端输入命令:如

$ pod search AFNetworking


会显示出AFNetworking相关的库

Creating search index for spec repo 'master'.. Done!

- Versions: 0.0.2, 0.0.1 [master repo]

-> AFHARchiver (0.2.2)
An AFNetworking extension to automatically generate a HTTP Archive file of
all of your network requests.
pod 'AFHARchiver', '~> 0.2.2'
- Homepage: https://github.com/mutualmobile/AFHARchiver - Source:   https://github.com/mutualmobile/AFHARchiver.git - Versions: 0.2.2, 0.2.1, 0.2.0, 0.1.0, 0.0.2, 0.0.1 [master repo]

-> AFHTTPClientLogger (0.7.0)
AFNetworking Extension for request logging.
pod 'AFHTTPClientLogger', '~> 0.7.0'
- Homepage: https://github.com/jparise/AFHTTPClientLogger - Source:   https://github.com/jparise/AFHTTPClientLogger.git - Versions: 0.7.0, 0.6.1, 0.6.0, 0.5.0 [master repo]


(2)在工程中创建一个Podfile文件,在终端输入命令

$cd /Users/jh/Desktop/project/CocoaPods
$ touch Podfile


备注:/Users/jh/Desktop/project/CocoaPods为需要安装库文件项目的路径,根据自己的实际情况而定!

(3)使用Xcode打开Podfile,然后按如下格式编辑Podfile,保存。

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
pod "AFNetworking", "~> 2.5.4"
pod 'SDWebImage'
pod 'KVNProgress'

target 'CocoaPods' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!

# Pods for CocoaPods

end


(4)安装第三方库,在终端输入命令

$ pod install


三、可能遇到的问题

(1)使用cocoapods导入第三方类库后头文件没有代码提示?

解决办法: 选择Target -> Build Settings 菜单,找到\”User Header Search Paths\”设置项,新增一个值”${SRCROOT}”,并且选择\”Recursive\”

(2)出现如下警告

[!] Your Podfile has had smart quotessanitised. To avoid issues in the future, you should not use TextEdit forediting it. If you are not using TextEdit, you should turn off smart quotes inyour editor of choice.


解决办法:不要使用文本编辑去编辑Podfile,使用Xcode编辑,或者使用终端敲命令去编辑。

(3)执行pod install 或pod update 命令后,updating local specsrepositories 卡住不动

解决办法:pod install 被墙了,换成新的命令pod install –verbose –no-repo-update

(4)项目运行时报错:

Thefile “Pods.xcconfig” couldn’t be opened because there is no such file.


解决办法:pod update就可以了。

(5)在运行“sudo gem install cocoapods” 的时候出现问题:

ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fuzzy_match


则可以改为:

sudo gem install -n /usr/local/bin cocoapods
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gem ruby CocoaPods