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

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

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


当前回答

容器安装

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 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 Once done, it will output "Setup Complete", and you can create your Xcode project and save it. Then in the terminal, cd to your Xcode project root directory (where your .xcodeproj file resides) and type: pod init Then open your project's podfile by typing in terminal: open -a Xcode Podfile 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 use_frameworks! if you're using Swift When you are done editing the podfile, save it and close Xcode. Then install pods into your project by typing in terminal: pod install or (For m1 chip) arch -x86_64 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.)

其他回答

打开终端 在终端输入$ sudo gem install cocoapods命令 创建新的Xcode项目 导航到包含Xcode项目的目录。使用cd " ../directory-location/..或CD[拖放项目文件夹] 圆荚体安装

如果此提示错误,无法添加带有url的源..然后安装Xcode的命令行工具。再次,重新运行Pod安装命令。

这也将安装所有依赖项。

现在,在工作区中打开你的项目,即项目名称。xcworkspace而不是Project-Name.xcodeproj

CocoaPods安装在macOS v10.13 (High Sierra)上:

安装Homebrew - https://brew.sh/ 在终端执行以下命令: Sudo gem update—system Sudo gem install activesupport -v 4.2.6 Sudo gem install -n /usr/local/bin cocoapods . sh 舱设置 Pod设置—详细

如果您想为您的项目第一次安装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

对于终端中的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

安装pod文件的简单步骤:

打开终端 终端命令:sudo gem install cocoapods 在终端中设置项目路径。 命令:pod init 转到项目的pod文件,并添加要安装的pod 添加到pod文件:pod 'AFNetworking', '~> 3.0 . 命令:Pod install 关闭Xcode项目 从终端打开项目 命令:打开PodDemos.xcworkspace