关于cocoaPods安装与使用

来源:互联网 发布:知乎的运营模式 编辑:程序博客网 时间:2024/05/19 00:14

1.开启 terminal
2.移除现有 Ruby 默认源
$ gem sources –remove https://rubygems.org/

3.使用新的源
$ gem sources -a https://ruby.taobao.org/

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

5.安装 CocoaPods
$ sudo gem install cocoapods

$ pod setup

备注:苹果系统升级 OS X EL Capitan 后安装改为:

$ sudo gem install -n /usr/local/bin cocoapods

$ pod setup

6.更新 gem
$ sudo gem update –system

7.新建工程,并在终端用 cd 指令到文件夹内
$ pod search 第三方

8.新建 Podfile 文件
$ touch Podfile

9.编辑 Podfile 文件,并写入要添加的第三方库
platform:ios, ‘8.0’

pod ‘AFNetworking’, ‘~> 2.3.1’<——-第三方

10.导入第三方库
$ pod install

$ pod install –verbose –no-repo-update

11.退出终端

可能遇到的错误提示及解决方法:
Error 1:
Error fetching http://ruby.taobao.org/:

bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)

解决方案:把安装流程中 $ gem sources -a http://ruby.taobao.org/

改为:$ gem sources -a https://ruby.taobao.org/

Error 2:
ERROR: While executing gem … (Errno::EPERM)

Operation not permitted - /usr/bin/pod

解决方案:苹果系统升级 OS X EL Capitan 后会出现的插件错误,将安装流程 5.安装 CocoaPods 的 sudo gem install cocoapods

改为 sudo gem install -n /usr/local/bin cocoapods

Error 3:
[!] Unable to satisfy the following requirements:

  • AFNetworking (~> 2.3.1) required by Podfile

Specs satisfying the AFNetworking (~> 2.3.1) dependency were found, but they required a higher minimum deployment target.

解决方案:Podfile 文件 中 platform:ios, ‘8.0’ 后边的 8.0 是平台版本号 ,一定要加上

0 0
原创粉丝点击