关于CocoaPods的一些低级的使用

前言:

这里主要介绍CocoaPods的安装和一些简单的用法。

cocoapods为IOS程序提供依赖管理工具。

  • 安装,使用mac自带的ruby的gem命令下载安装:
    如果你的gem太老了,可能会出现问题可以尝试升级gem
    sudo gem update --system
    另外ruby的软件源rubygems.org使用的是国外的云服务,所以被墙了,需要换成国内淘宝的源:
    被墙可能会出现这样子的提示:

      $ sudo gem install cocoapods
      ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
    Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/quick/Marshal.4.8/cocoapods-0.35.0.gemspec.rz)
    
- 把原来的源删除掉

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

- 加个新的源

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

这边可能会出现下面的问题

Error fetching https://ruby.taobao.org/:
no such name (https://ruby.taobao.org/specs.4.8.gz)

具体原因我也是不懂,不过你多浓几次步骤2.加个新的源就可以了。(我的是这样子的)

- 成功以后的结果是这样子的

        $ gem sources -a https://ruby.taobao.org
        https://ruby.taobao.org added to sources
- 查看当前的源是不是刚替换的那个

        $ gem sources -l
        *** CURRENT SOURCES ***

        https://ruby.taobao.org
- 成功以后使用如下的命令行执行安装

        $ sudo gem install cocoapods

安装的过程一般会很长,我以前大概等了有4个小时吧
完成后有20 gems installed

- 执行pod setup这时候有可能会出现下面的东西

        $ pod setup
        Setting up CocoaPods master repo
        [!] /usr/bin/git clone 'https://github.com/CocoaPods/Specs.git' master --depth=1

        Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

虽然不知道是什么意思,大致应该是让我同意xcode的什么东西,于是我安装了cxode然后再执行pod setup

pod setup
Setting up CocoaPods master repo

CocoaPods 0.36.0.beta.2 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Setup completed

到此算是完成了,键入pod search json看看是不是能列出一大堆的第三方开源类库,有的话就说明安装成功了。

  • 使用cocoapods的镜像索引
  • 使用cocoapods

    • 不更新podspec
      cocoapods在执行pod installpod update时,会默认先更新一次podspec索引。使用--no-repo-update参数可以禁止其做索引更新操作。如下所示

      $ pod install --no-repo-update
      $ pod update --no-repo-update
      

      使用时需要新建一个名为Podfile的文件,如以下格式,将要依赖的库名字依次列在文件中

      platform :ios, '7.0'
      
      pod 'TBXML', '~> 1.5'
      
      pod 'ASIHTTPRequest', '~> 1.8.2'
      
pod 'SSKeychain', '~> 1.2.2'

然后将你编辑好的Podfile文件放到你项目根目录中,执行如下命令就好:

cd "you project home"
pod install

然后就是等了。
如果你的所有第三方库都已经下载完成并且设置号了编译参数和依赖,要记住如下2点:

  • 使用Cocoapods生成的.xcworkspace文件来打开工程,而不是以前的.xcodeproj文件
  • 每次更改了Podfile文件,你需要重新执行一次pod update命令。

可能更新之后会出现这样子的问题

当不小心在工程文件中删掉文件时。有可能会提示.xxx is missing from working copy.有可能是SVN引起的。删掉这个文件就好了. 如果是单个文件。
删除方法为:

These solutions are way too difficult. The problem is that you have removed the project from filesystem but SVN still thinks they are there. Detaching project from SVN will work, the same for removing .svn folders BUT that is going to destroy your repository!
It is much easier to open console, browse to your folder ("cd /pathToYourFolder") and type the following command:
svn delete nameOfMissingFile
If the name of your missing file includes the @ character (eg: retina-specific artwork), ensure the file name terminates with the @ symbol:
svn delete nameOfMissingFile@2x.png@
For GIT repositories:
git rm nameOfMissingFile

(命令行中 cd到你的missingfile的文件路径下,然后svn delete youmissingfilename
以下是原网页截取下来的:

        http://stackoverflow.com/questions/5292291/missing-file-warnings-showing-up-after-upgrade-to-xcode-4


        17

        I had the same issue and resolved it via Terminal using: svn rm --force nameOfMissingFile – ReachWest Mar 22 '11 at 21:06
        1

        This is a better answer than the one marked as correct. Deleting SVN folders from a project under SVN control can be a whole world of pain. Best to use SVN to solve the issue. I followed this answer to resolve my own problem, however I had the luxury of Cornerstone. But otherwise cool. Thanks :) –  jowie Jul 8 '11 at 10:52
        1

        This doesn't seem to be working for me. I would add the file back, and then delete it, but the same warning still shows up in the build. I even tried to add the files back to the project and then delete them. Still the same problem. –  Yenyi Aug 31 '11 at 20:29
        8

        It worked for me, but i first had to create a dummy file there before i could delete if using svn. So you have to do touch nameOfMissingFile and then svn delete nameOfMissingFile --force –  Maciej Swic Mar 4 '12 at 14:59
5

        I additionally had to quit and kill xcode for the problem to go away. –  Twilite Apr 3 '12 at 16:3
Zerlz wechat
扫码关注一个很懒的程序员!
Winter is coming, give me a penny!