我参考了许多链接并尝试了,但我没有成功。我阅读了CocoaPods文档,并多次尝试安装,但总是因为初始步骤而失败。我发现了一个错误,我不能先安装宝石。一个一个的步骤是什么?例如如何安装的步骤或演示。

这是我尝试过的一个链接。

截图指的是我得到的这个控制台错误:


当前回答

Pod安装在Mac OS X v10.11.2 (El Capitan)上出现错误:

安装cocoapods时出错: activesupport要求Ruby版本>= 2.2.2。

在得到这个错误后,我尝试了这个命令并重新安装。这对我很管用。

sudo gem install activesupport -v 4.2.6

现在尝试相同的pod安装命令

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

其他回答

对于终端中的CocoaPods,请遵循以下命令:

sudo gem update

sudo gem install cocoapods

pod setup

cd (project direct drag link)

pod init

open -aXcode podfile # (If it’s already open, add your pod file name. Example: alamofire4.3)

pod install

pod update

这些是我通常遵循的完整步骤。我把这些步骤写得尽可能短,假设你了解Mac和Xcode项目。首先,打开终端,使用以下命令,每个命令后按enter键。

如果你还没有安装CocoaPods,输入以下命令:

sudo gem install cocoapods

现在请使用以下命令移动到您的Xcode项目目录,并将/您的Xcode项目目录路径替换为该目录的实际路径:

cd /Your Xcode Project Directory Path

下面是如何使用CocoaPods的说明。输入到终端的每个命令执行成功后,请等待一段时间。

Searching for pods in terminal: pod search networking (replace networking with which you want to search) Creating the pod file: pod init Opening the pod file: open -a Xcode Podfile Adding the pods: (After adding your pods you must save the podfile first and then head back to the terminal again.) target 'WebServiceUsingMantleAFNetworking' do # platform :ios, '8.0' //Choose your version of iOS pod 'AFNetworking', '~> 2.6.0’ end OR platform :ios, '8.0' pod 'AFNetworking' pod 'Mantle' pod 'LBBlurredImage' pod 'TSMessages' pod 'ReactiveCocoa' Installing the pods: pod install Check for updates of pods on existing project: pod outdated Update the existing pods: pod update Uninstall the Cocoapods from system: sudo gem uninstall cocoapods There is a complete tutorial for removing pods from your Xcode project on Stack Overflow. You can check on this following link for more info. How to remove CocoaPods from a project?

如果您想为您的项目第一次安装CocoaPods。

示例:在这里,我们将使用CocoaPods逐步安装“Alamofire”SDK。

步骤1。打开终端,点击命令,然后按Enter键

sudo gem install cocoapods

步骤2。如果它要求,您应该提供系统密码,然后按Enter键

步骤3。使用命令“cd”并给出项目的路径,然后按Enter键

注意:输入“cd”命令,然后空格并拖动项目文件夹到终端。它将采取如下所示的项目路径(这里我的项目名称是:Simple Alamofire)

cd  /Users/ramdhanchoudhary/Documents/Swift\ Workspace/Simple\
Alamofire

步骤4。在你的项目中通过终端通过命令“touch Podfile”并按“Enter”创建一个pod文件

touch Podfile

第5步。然后用终端命令“open Podfile”打开“Podfile”,按“Enter”键

open Podfile

步骤6。现在在打开的pod文件中输入以下代码,然后保存并关闭文件

source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '10.0'
    use_frameworks!

    target '<Your Target Name>' do
            pod 'Alamofire', '~> 4.0'
    end

步骤7。回到终端键入命令“Pod install”,然后按Enter键。

Pod install

步骤8。等待安装完成100%,大约650+ MB

第9步。这就是它去项目文件夹,并打开下面的文件

<your project name>.xcworkspace

第10步。导入Alamofire类并使用!!

import Alamofire

2020年,在macOS v10.15 (Catalina)中安装CocoaPods v1.9.1

首先在Mac上使用终端设置Xcode版本。 sudo xcode-select -switch /Applications/Xcode.app 接下来,使用终端安装CocoaPods。 Sudo gem安装cocoapods

更多信息,请访问官方网站https://cocoapods.org/。

如果你在代理后面,那么将代理作为参数传递:

sudo gem install --http-proxy http://user:password@www-proxy.example.com:80 cocoapods