美文网首页
安装 CocoaPods

安装 CocoaPods

作者: 言肆_ | 来源:发表于2019-03-07 15:19 被阅读0次

第一步:安装ruby

安装CocoaPods,需要ruby环境,可以通过终端命令查看

gem sources -l //查看ruby源

默认情况下,显示

*** CURRENT SOURCES ***

https://rubygems.org/

修改当前ruby源(以默认情况为例, 显示什么remove后接什么地址)

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

gem sources -a https://gems.ruby-china.com

通过终端命令验证当前ruby源是否修改成功.

gem sources -l //查看ruby源

终端显示 https://gems.ruby-china.com,证明我们ruby源修改成功

$  ~ gem sources -l

*** CURRENT SOURCES ***

https://gems.ruby-china.com

第二步:升级Gem

Gem 是 Ruby 模块 (叫做 Gems) 的包管理器。其包含包信息,以及用于安装的文件。

为了防止Gem版本偏低导致安装CocoaPods报错, 需要升级Gem.

sudo gem update --system   //升级gem

第三步:安装CocoaPods

Mac OS X 10.11前  输入:

sudo gem install cocoapods

Mac OS X 10.11后  输入:

sudo gem install -n /usr/local/bin cocoapods --pre //安装最新版本

如需要安装指定版本pods命令行为:

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

执行成功后,控制台输入:

pod setup 

这条命令是将Github上的开源库都托管都安装Podspec索引安装到到本地.

执行完毕后,可以通过以下命令查看版本

pod --version

到这里也就安装完毕了,可以 cd到你的项目路径里面来安装第三方.

第四步:安装第三方框架

进入要安装框架的项目的.xcodeproj同级文件夹,在该目录下输入:

pod init

这个时候项目文件夹汇总会出现Podfile文件;

打开Podfile,

# Uncomment the next line to define a global platform for your project

# platform :ios, '9.0'

target 'test' do

  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks

  use_frameworks!

  # Pods for test

end

把我们需要的第三方框架写入以Alamofire为例,取消platform :ios, '9.0' 的注释

# Uncomment the next line to define a global platform for your project

platform :ios, '9.0'

target 'test' do

pod 'Alamofire',  '~>4.8.1'

  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks

  use_frameworks!

  # Pods for test

end

 podfile文件解释

platform : ios, '9.0'代表当前第三方支持最低版本是iOS 9.0;

use_frameworks ,如果您不使用swift并且不想使用动态框架需要注释掉。

 pod 'Alamofire', '~> 4.8.1'  ,导入Alamofire 4.8.1版本的第三方

保存Podfile文件,执行

pod install 

CocoaPods安装完毕.

$ test pod install

Analyzing dependencies

Downloading dependencies

Installing Alamofire (4.8.1)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

相关文章

网友评论

      本文标题:安装 CocoaPods

      本文链接:https://www.haomeiwen.com/subject/gcpmxttx.html