如何安装 CocoaPods? [英] How do I install CocoaPods?

查看:35
本文介绍了如何安装 CocoaPods?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参考了很多链接并尝试过,但没有成功.阅读CocoaPods文档,多次尝试安装,但总是因为启动步骤失败.我发现了一个错误,我无法先安装 gems.一步一步是什么步骤?如安装步骤或演示.

(El Capitan),输入:

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

如果出现错误activesupport requires Ruby version >= 2.xx",则首先通过在终端中键入来安装最新的 activesupport.

sudo gem install activesupport -v 4.2.6

  • 安装后,会有很多提示.阅读它们,如果没有发现错误,则表示 CocoaPods 安装完成.接下来,您需要设置 CocoaPods 主存储库.在终端输入:

    pod 设置

    等待它下载主存储库.大小非常大(2016 年 12 月为 370.0 MB).所以可能需要一段时间.您可以通过打开 Activity 并转到 Network 选项卡并搜索git-remote-https"来跟踪下载.或者,您可以尝试添加--verbose"像这样的命令:

    pod setup --verbose

  • 完成后,它会输出Setup Complete",您可以创建您的 Xcode 项目并保存它.

  • 然后在终端中,cd 到您的 Xcode 项目根目录(您的 .xcodeproj 文件所在的位置)并键入:

    pod init

  • 然后通过在终端中输入以下内容打开项目的 podfile:

    open -a Xcode Podfile

  • 您的 Podfile 将以文本模式打开.最初会有一些默认命令在那里.您可以在此处添加项目的依赖项.例如,在 podfile 中,输入

    pod 'AFNetworking', '0.9.1'

    (这一行是将 AFNetworking 库添加到您的项目的示例.)

    其他提示:

    取消注释 platform :ios, '9.0'
    如果您使用的是 Swift,请取消注释 user_frameworks!

    完成 podfile 编辑后,保存并关闭 Xcode.

  • 然后通过在终端中输入以下内容将 Pod 安装到您的项目中:

    pod install

    根据您为项目添加到 podfile 中的库数量,完成此操作的时间会有所不同.完成后,会有一条消息说

    <块引用>

    "Pod 安装完成!Podfile 中有 X 个依赖项并且总共安装了 X 个 Pod."

    现在关闭您的 Xcode 项目.然后定位并打开.xcworkspace Xcode 项目文件并开始编码.(您不应再打开 xcodeproj 文件.)

  • I referred to many links and tried, but I had no success. I read CocoaPods documents and many times tried to install, but I always failed because of the starting steps. I found one error whereby I can't install gems first. What are the steps one by one? Such as steps or a demo of how to install.

    This is one link which I tried.

    The screenshot refers to this console error I was given:

    解决方案

    POD Install

    1. Open terminal and type:

      sudo gem install cocoapods
      

      The Gem will get installed in Ruby inside the System library. Or try on Mac OS X v10.11 (El Capitan), type:

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

      If there is an error "activesupport requires Ruby version >= 2.xx", then install latest activesupport first by typing in the terminal.

      sudo gem install activesupport -v 4.2.6
      

    2. After installation, there will be a lot of messages. Read them and if no error found, it means the CocoaPods installation is done. Next, you need to setup the CocoaPods master repository. Type in the terminal:

      pod setup
      

      And wait it will download the master repository. The size is very big (370.0 MB in December 2016). So it can be a while. You can track of the download by opening Activity and go to the Network tab and search for "git-remote-https". Alternatively, you can try adding "--verbose" to the command like so:

      pod setup --verbose
      

    3. Once done, it will output "Setup Complete", and you can create your Xcode project and save it.

    4. Then in the terminal, cd to your Xcode project root directory (where your .xcodeproj file resides) and type:

      pod init
      

    5. Then open your project's podfile by typing in terminal:

      open -a Xcode Podfile
      

    6. Your Podfile will get open in text mode. Initially there will be some default commands in there. Here is where you add your project's dependencies. For example, in the podfile, type

      pod 'AFNetworking', '0.9.1'
      

      (This line is an example of adding the AFNetworking library to your project.)

      Other tips:

      Uncomment platform :ios, '9.0'
      Uncomment user_frameworks! if you're using Swift

      When you are done editing the podfile, save it and close Xcode.

    7. Then install pods into your project by typing in terminal:

      pod install
      

      Depending how many libraries you added to your podfile for your project, the time to complete this varies. Once completed, there will be a message that says

      "Pod installation complete! There are X dependencies from the Podfile and X total pods installed."

      Now close your Xcode project. Then locate and open the .xcworkspace Xcode project file and start coding. (You should no longer open the xcodeproj file.)

    这篇关于如何安装 CocoaPods?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆