Cocopods安装使用和错误

Cocopods的安装

CocoaPods应该是iOS最常用最有名的类库管理
当我们开发iOS应用时,会经常使用到很多第三方开源类库,比如AFNetWorking等等,可能某个类库又用到其他的库,手动一个个去下载所需类库十分麻烦。如果我们项目中用到的类库有更新,还要重新下载新版本,重新加入到项目中,十分麻烦。所以,我们需要 CocoaPods帮我们管理。
如何下载和安装CocoaPods?
在安装CocoaPods之前,首先要在本地安装好Ruby环境。至于如何在Mac中安装好Ruby环境,请找度娘和谷哥。
假如你在本地已经安装好Ruby环境,那么下载和安装CocoaPods将十分简单,只需要一行命令。在Terminator中输入以下命令:

         sudo gem install cocoapods

但是,在终端中敲入这个命令之后,可能半天没有任何反应。

这时我们可以用淘宝的Ruby镜像来访问cocoapods。按照下面的顺序在终端中敲入依次敲入命令:

        $ gem sources --remove https://rubygems.org/

//等有反应之后再敲入以下命令

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

为了验证你的Ruby镜像是并且仅是taobao,可以用以下命令查看:

       $ gem sources -l

只有在终端中出现下面文字才表明你上面的命令是成功的:

      *** CURRENT SOURCES ***
      https://ruby.taobao.org/

这时候,我们再次在终端中运行:

        $ sudo gem install cocoapods

        $ pod setup

等一会,CocoaPods就可以在你本地下载并且安装好了

安装时候遇到的问题:
Setting up CocoaPods master repo
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git  master --depth=1

Cloning into 'master'...
error: RPC failed; result=18, HTTP code = 200
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
解决办法:
$ git config --global http.postBuffer 24288000
$ git config --list

会输出:http.postbuffer=24288000

再次执行:

$ pod setup
Cocopods使用

我们想用CocoaPods,在项目中导入ASIHTTPRequest类库
首先,我们要确定ASIHTTPRequest是否支持CocoaPods,可以用CocoaPods的搜索功能验证一下。在终端中输入:

       $ pod search ASIHTTPRequest

输入之后,你会在终端中看到关于ASIHTTPRequest类库的一些信息。
比如:

       -> ASIHTTPRequest (1.8.2)
          Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac    OS X and  iPhone.
          pod 'ASIHTTPRequest', '~> 1.8.2'
          - Homepage: http://allseeing-i.com/ASIHTTPRequest
          - Source:   https://github.com/pokeb/asi-http-request.git
          - Versions: 1.8.2, 1.8.1 [master repo]
          - Sub specs:
          - ASIHTTPRequest/Core (1.8.2)
          - ASIHTTPRequest/ASIWebPageRequest (1.8.2)
          - ASIHTTPRequest/CloudFiles (1.8.2)
          - ASIHTTPRequest/S3 (1.8.2)

现在知道ASIHTTPRequest支持Cocopods了,我们就要道你的项目中创建一个文件,这个文件就叫做“Podfile”,一定得是这个文件名,而且没有后缀。在里面添加pod 'ASIHTTPRequest', '~> 1.8.2',就是告诉CocoaPods,我们要下载ASIHTTPRequest ,1.8.2版本

我们先创建这个PodFile文件。在终端中进入(cd命令)你项目所在目录,然后在当前目录下,利用vim创建Podfile,运行:

       $ vim Podfile

然后在Podfile文件中输入以下文字:

       pod "ASIHTTPRequest", "~> 1.8.2"

然后保存退出。vim环境下,保存退出命令是:

       :wq!

我们会发现项目中,多了一个名字为Podfile的文件,而且文件内容就是输入的内容。注意,Podfile文件应该和你的工程文件.xcodeproj在同一个目录下。

下面我们就可以利用CocoPods下载ASIHTTPRequest类库了。还是在终端中的当前项目下,运行命令:

      $ pod install

运行完命令之后,会看见有这句话[!] From now on use ********.xcworkspace这是说:以后打开项目就用 **.xcworkspace 打开,而不是之前的**.xcodeproj文件。

现在,我们就可以开始使用ASIHTTPRequest啦。可以测试一下,在项目中输入:
#import <AFNetworking.h>或者#import "AFNetworking.h"试试

如果以后有更新 或者 添加别的类库,用update命令即可:

       $ pod update
CocoaPods 报错

Xcode 升级到 6.0 后,更新 CocoaPods 或者以前手动添加过第三方SDK改用Cocopods,可能会出现以下的错误

错误1:
     [!] The `Paopao [Debug]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

    [!] The `Paopao [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

      [!] The `Paopao [Release]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

       [!] The `Paopao [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

产生此警告的原因是项目 Target 中的一些设置,CocoaPods 也做了默认的设置,如果两个设置结果不一致,就会造成问题。

我想要使用 CocoaPods 中的设置,分别在我的项目中定义PODS_ROOT 和 Other Linker Flags的地方,把他们的值用$(inherited)替换掉,进入终端,执行

      pod update

警告没了

我个人更喜欢一种简单粗暴的方法:

点击项目文件 project.xcodeproj,右键显示包内容,用文本编辑器打开project.pbxproj,删除OTHER_LDFLAGS的地方,保存,pod update,警告没了。。。。

错误2:

错误

这个解决也比较简单,
在Build Setting 中的Other Linker Flags选项中加入$(OTHER_LDFLAGS) 如图:


解决错误

编译通过.........

OS X EI Caption系统下遇到的问题

升级OS X EI Capiton之后,发现CocoaPods的pod命令无效了,提示一下错误

pod: command not found

解决步骤:
1.卸载

sudo gem uninstall cocoapods

2.重新安装

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

3.如果没有权限执行pod,执行命令一下命令赋予/usr/local/bin给予执行与读取权限

sudo chmod +rx /usr/local/bin/

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值